feat(writer): Add read/write retry delays (#1919)

Change-Type: minor
This commit is contained in:
Jonas Hermsmeier 2017-12-15 16:09:11 +01:00 committed by GitHub
parent b086e4c2a1
commit 74c0c13fbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -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'

View File

@ -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'