From 74c0c13fbdeab77d29f3b34df56703ce0d2d42b5 Mon Sep 17 00:00:00 2001 From: Jonas Hermsmeier Date: Fri, 15 Dec 2017 16:09:11 +0100 Subject: [PATCH] feat(writer): Add read/write retry delays (#1919) Change-Type: minor --- lib/writer/block-read-stream.js | 11 ++++++++++- lib/writer/block-write-stream.js | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/writer/block-read-stream.js b/lib/writer/block-read-stream.js index 1af849b5..63a902aa 100644 --- a/lib/writer/block-read-stream.js +++ b/lib/writer/block-read-stream.js @@ -24,6 +24,13 @@ const errors = require('./error-types') const CHUNK_SIZE = 64 * 1024 const MIN_CHUNK_SIZE = 512 +/** + * @summary I/O retry base timeout, in milliseconds + * @constant + * @type {Number} + */ +const RETRY_BASE_TIMEOUT = 100 + /** * @summary BlockReadStream * @class @@ -91,7 +98,9 @@ class BlockReadStream extends stream.Readable { if (isTransient && (this.retries < this.maxRetries)) { this.retries += 1 - this._read() + setTimeout(() => { + this._read() + }, RETRY_BASE_TIMEOUT * this.retries) return } else if (isTransient) { error.code = 'EUNPLUGGED' diff --git a/lib/writer/block-write-stream.js b/lib/writer/block-write-stream.js index 263c5e96..c241183e 100644 --- a/lib/writer/block-write-stream.js +++ b/lib/writer/block-write-stream.js @@ -25,6 +25,13 @@ const errors = require('./error-types') const CHUNK_SIZE = 64 * 1024 const UPDATE_INTERVAL_MS = 500 +/** + * @summary I/O retry base timeout, in milliseconds + * @constant + * @type {Number} + */ +const RETRY_BASE_TIMEOUT = 100 + /** * @summary BlockWriteStream * @class @@ -154,7 +161,9 @@ class BlockWriteStream extends stream.Writable { if (isTransient && (this.retries < this.maxRetries)) { this.retries += 1 - this._write(chunk, encoding, next) + setTimeout(() => { + this._write(chunk, encoding, next) + }, RETRY_BASE_TIMEOUT * this.retries) return } else if (isTransient) { error.code = 'EUNPLUGGED'