Skip to content

Commit d4171e0

Browse files
ronagjuanarbol
authored andcommittedApr 28, 2022
stream: resume stream on drain
Previously we would just resume "flowing" the stream without reseting the "paused" state. Fixes this by properly using pause/resume methods for .pipe. Fixes: #41785 PR-URL: #41848 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 7f2825b commit d4171e0

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed
 

‎lib/internal/streams/readable.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -807,8 +807,7 @@ function pipeOnDrain(src, dest) {
807807

808808
if ((!state.awaitDrainWriters || state.awaitDrainWriters.size === 0) &&
809809
EE.listenerCount(src, 'data')) {
810-
state.flowing = true;
811-
flow(src);
810+
src.resume();
812811
}
813812
};
814813
}

‎test/parallel/test-stream-readable-pause-and-resume.js

+16
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,19 @@ function readAndPause() {
5656
assert(readable.isPaused());
5757
});
5858
}
59+
60+
{
61+
const { PassThrough } = require('stream');
62+
63+
const source3 = new PassThrough();
64+
const target3 = new PassThrough();
65+
66+
const chunk = Buffer.allocUnsafe(1000);
67+
while (target3.write(chunk));
68+
69+
source3.pipe(target3);
70+
target3.on('drain', common.mustCall(() => {
71+
assert(!source3.isPaused());
72+
}));
73+
target3.on('data', () => {});
74+
}

0 commit comments

Comments
 (0)
Please sign in to comment.