Skip to content

Commit 12253f8

Browse files
ronagMylesBorins
authored andcommitted
stream: sync stream unpipe resume
pipe() ondata should not control flow state if cleaned up. Fixes: #31190 Backport-PR-URL: #32264 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]> Backport-PR-URL: #32264
1 parent 885c88e commit 12253f8

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Diff for: lib/_stream_readable.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,9 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
705705
debug('false write response, pause', state.awaitDrain);
706706
state.awaitDrain++;
707707
}
708+
if (!cleanedUp) {
709+
src.pause();
710+
}
708711
if (!ondrain) {
709712
// When the dest drains, it reduces the awaitDrain counter
710713
// on the source. This would be more elegant with a .once()
@@ -713,7 +716,6 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
713716
ondrain = pipeOnDrain(src);
714717
dest.on('drain', ondrain);
715718
}
716-
src.pause();
717719
}
718720
}
719721

Diff for: test/parallel/test-stream-readable-unpipe-resume.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const stream = require('stream');
5+
const fs = require('fs');
6+
7+
const readStream = fs.createReadStream(process.execPath);
8+
9+
const transformStream = new stream.Transform({
10+
transform: common.mustCall(() => {
11+
readStream.unpipe();
12+
readStream.resume();
13+
})
14+
});
15+
16+
readStream.on('end', common.mustCall());
17+
18+
readStream
19+
.pipe(transformStream)
20+
.resume();

0 commit comments

Comments
 (0)