Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit d710bf5

Browse files
Merge pull request #61 from adipirro/patch-1
NullStream write after end fix
2 parents c65140c + df1b302 commit d710bf5

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

lib/server/command_processor.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ const kSource = Symbol("source");
99
const kCache = Symbol("cache");
1010
const kSendFileQueue = Symbol("sendFileQueue");
1111

12-
class NullStream extends Writable {
13-
_write(chunk, encoding, cb) {
14-
setImmediate(cb);
15-
}
16-
}
17-
1812
class CommandProcessor extends Duplex {
1913

2014
/**
@@ -45,7 +39,6 @@ class CommandProcessor extends Duplex {
4539
this._putWhitelist = this._options.putWhitelist;
4640
this._whitelistEmpty = (!Array.isArray(this._putWhitelist) || !this._putWhitelist.length);
4741

48-
this._nullStream = new NullStream();
4942
this._putStream = null;
5043
this._putSize = 0;
5144
this._putSent = 0;
@@ -351,7 +344,11 @@ class CommandProcessor extends Duplex {
351344
if (this._isWhitelisted(this._trx.clientAddress)) {
352345
this._putStream = await this._trx.getWriteStream(type, size);
353346
} else {
354-
this._putStream = this._nullStream;
347+
this._putStream = new Writable({
348+
write(chunk, encoding, cb) {
349+
setImmediate(cb);
350+
}
351+
});
355352
helpers.log(consts.LOG_DBG, `PUT rejected from non-whitelisted IP: ${this._trx.clientAddress}`);
356353
}
357354

@@ -361,4 +358,4 @@ class CommandProcessor extends Duplex {
361358
}
362359
}
363360

364-
module.exports = CommandProcessor;
361+
module.exports = CommandProcessor;

0 commit comments

Comments
 (0)