Skip to content

Commit

Permalink
stream: fix not calling cleanup() when unpiping all streams.
Browse files Browse the repository at this point in the history
Refs: #12746
  • Loading branch information
陈刚 committed Jan 20, 2018
1 parent e1c29f2 commit 3500d5f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ Readable.prototype.unpipe = function(dest) {
state.flowing = false;

for (var i = 0; i < len; i++)
dests[i].emit('unpipe', this, unpipeInfo);
dests[i].emit('unpipe', this, { hasUnpiped: false });
return this;
}

Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-stream-pipe-unpipe-streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,26 @@ source.unpipe(dest2);
source.unpipe(dest1);

assert.strictEqual(source._readableState.pipes, null);

{
// unpipe all
const source = Readable({ read: () => {} });
const dest1 = Writable({ write: () => {} });
const dest2 = Writable({ write: () => {} });

source.pipe(dest1);
source.pipe(dest2);

checkDestCleanup(dest1);
checkDestCleanup(dest2);

source.unpipe();

function checkDestCleanup(dest) {
const unpipeChecker = common.mustCall(() => {
dest.removeListener('unpipe', unpipeChecker);
assert.strictEqual(dest.listenerCount('unpipe'), 0);
});
dest.on('unpipe', unpipeChecker);
}
}

0 comments on commit 3500d5f

Please sign in to comment.