stream: emit 'pause' on unpipe

unpipe should use pause() instead of mutating
state.flowing directly so that pausing side
effects such as emitting 'pause' are properly
performed.

Fixes: https://github.com/nodejs/node/issues/32470

PR-URL: https://github.com/nodejs/node/pull/32476
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
Robert Nagy 2020-03-25 00:43:18 +01:00 committed by Myles Borins
parent b2e1a01516
commit 0d0f151a46
No known key found for this signature in database
GPG key ID: 933B01F40B5CA946
2 changed files with 12 additions and 2 deletions

View file

@ -819,7 +819,7 @@ Readable.prototype.unpipe = function(dest) {
// remove all.
var dests = state.pipes;
state.pipes = [];
state.flowing = false;
this.pause();
for (const dest of dests)
dest.emit('unpipe', this, { hasUnpiped: false });
@ -833,7 +833,7 @@ Readable.prototype.unpipe = function(dest) {
state.pipes.splice(index, 1);
if (state.pipes.length === 0)
state.flowing = false;
this.pause();
dest.emit('unpipe', this, unpipeInfo);