Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
stream: sync stream unpipe resume
pipe() ondata should not control flow state if cleaned up.

Fixes: #31190

PR-URL: #31191
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Backport-PR-URL: #32264
  • Loading branch information
ronag committed Apr 1, 2020
commit 1cdf6f646771a0cd91efa9023440db8578304be1
4 changes: 3 additions & 1 deletion lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,9 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
debug('false write response, pause', state.awaitDrain);
state.awaitDrain++;
}
if (!cleanedUp) {
src.pause();
}
if (!ondrain) {
// When the dest drains, it reduces the awaitDrain counter
// on the source. This would be more elegant with a .once()
Expand All @@ -713,7 +716,6 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
ondrain = pipeOnDrain(src);
dest.on('drain', ondrain);
}
src.pause();
}
}

Expand Down
20 changes: 20 additions & 0 deletions test/parallel/test-stream-readable-unpipe-resume.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

const common = require('../common');
const stream = require('stream');
const fs = require('fs');

const readStream = fs.createReadStream(process.execPath);

const transformStream = new stream.Transform({
transform: common.mustCall(() => {
readStream.unpipe();
readStream.resume();
})
});

readStream.on('end', common.mustCall());

readStream
.pipe(transformStream)
.resume();