From f698d4427a616d0f20ba11d803325017aea47862 Mon Sep 17 00:00:00 2001 From: Anthony DiPirro Date: Tue, 18 Sep 2018 10:46:17 -0700 Subject: [PATCH 1/2] NullStream write after end fix Since the stream needs to be reused, make it bypass the normal end process and just keep on eating put requests. --- lib/server/command_processor.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/server/command_processor.js b/lib/server/command_processor.js index f6fdbd7..6df5989 100644 --- a/lib/server/command_processor.js +++ b/lib/server/command_processor.js @@ -13,6 +13,9 @@ class NullStream extends Writable { _write(chunk, encoding, cb) { setImmediate(cb); } + end(chunk, encoding, cb) { + if(cb) setImmediate(cb); + } } class CommandProcessor extends Duplex { @@ -361,4 +364,4 @@ class CommandProcessor extends Duplex { } } -module.exports = CommandProcessor; \ No newline at end of file +module.exports = CommandProcessor; From df1b30221a8ae6d233223f8e2ed75cb1f9571f51 Mon Sep 17 00:00:00 2001 From: Anthony DiPirro Date: Tue, 18 Sep 2018 23:06:05 -0700 Subject: [PATCH 2/2] Remove null stream and make the stream inline --- lib/server/command_processor.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib/server/command_processor.js b/lib/server/command_processor.js index 6df5989..23fd072 100644 --- a/lib/server/command_processor.js +++ b/lib/server/command_processor.js @@ -9,15 +9,6 @@ const kSource = Symbol("source"); const kCache = Symbol("cache"); const kSendFileQueue = Symbol("sendFileQueue"); -class NullStream extends Writable { - _write(chunk, encoding, cb) { - setImmediate(cb); - } - end(chunk, encoding, cb) { - if(cb) setImmediate(cb); - } -} - class CommandProcessor extends Duplex { /** @@ -48,7 +39,6 @@ class CommandProcessor extends Duplex { this._putWhitelist = this._options.putWhitelist; this._whitelistEmpty = (!Array.isArray(this._putWhitelist) || !this._putWhitelist.length); - this._nullStream = new NullStream(); this._putStream = null; this._putSize = 0; this._putSent = 0; @@ -354,7 +344,11 @@ class CommandProcessor extends Duplex { if (this._isWhitelisted(this._trx.clientAddress)) { this._putStream = await this._trx.getWriteStream(type, size); } else { - this._putStream = this._nullStream; + this._putStream = new Writable({ + write(chunk, encoding, cb) { + setImmediate(cb); + } + }); helpers.log(consts.LOG_DBG, `PUT rejected from non-whitelisted IP: ${this._trx.clientAddress}`); }