diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 9cf786a15be847..5761ce3a28615a 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -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; } diff --git a/test/parallel/test-stream-pipe-unpipe-streams.js b/test/parallel/test-stream-pipe-unpipe-streams.js index cd29b66365ae0f..431e34273e2b61 100644 --- a/test/parallel/test-stream-pipe-unpipe-streams.js +++ b/test/parallel/test-stream-pipe-unpipe-streams.js @@ -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); + } +}