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

Commit

Permalink
Merge pull request #61 from adipirro/patch-1
Browse files Browse the repository at this point in the history
NullStream write after end fix
  • Loading branch information
stephen-palmer authored Sep 19, 2018
2 parents c65140c + df1b302 commit d710bf5
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions lib/server/command_processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ const kSource = Symbol("source");
const kCache = Symbol("cache");
const kSendFileQueue = Symbol("sendFileQueue");

class NullStream extends Writable {
_write(chunk, encoding, cb) {
setImmediate(cb);
}
}

class CommandProcessor extends Duplex {

/**
Expand Down Expand Up @@ -45,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;
Expand Down Expand Up @@ -351,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}`);
}

Expand All @@ -361,4 +358,4 @@ class CommandProcessor extends Duplex {
}
}

module.exports = CommandProcessor;
module.exports = CommandProcessor;

0 comments on commit d710bf5

Please sign in to comment.