Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d4171e0

Browse filesBrowse files
ronagjuanarbol
authored andcommitted
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
Copy full SHA for d4171e0

File tree

Expand file treeCollapse file tree

2 files changed

+17
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+17
-2
lines changed
Open diff view settings
Collapse file

‎lib/internal/streams/readable.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/readable.js
+1-2Lines changed: 1 addition & 2 deletions
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
}
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-stream-readable-pause-and-resume.js
+16Lines changed: 16 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.