Skip to content

Commit

Permalink
stream: sync stream unpipe resume
Browse files Browse the repository at this point in the history
pipe() ondata should not control flow state if cleaned up.

Fixes: #31190

PR-URL: #31191
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
ronag authored and MylesBorins committed Jan 16, 2020
1 parent f62fb76 commit 256289f
Show file tree
Hide file tree
Showing 2 changed files with 21 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 @@ -740,6 +740,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
debug('false write response, pause', state.awaitDrainWriters.size);
state.awaitDrainWriters.add(dest);
}
src.pause();
}
if (!ondrain) {
// When the dest drains, it reduces the awaitDrain counter
Expand All @@ -749,7 +750,6 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
ondrain = pipeOnDrain(src, dest);
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();

0 comments on commit 256289f

Please sign in to comment.