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 46ed078

Browse filesBrowse files
ronagdanielleadams
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 77685d5 commit 46ed078
Copy full SHA for 46ed078

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
@@ -830,8 +830,7 @@ function pipeOnDrain(src, dest) {
830830

831831
if ((!state.awaitDrainWriters || state.awaitDrainWriters.size === 0) &&
832832
EE.listenerCount(src, 'data')) {
833-
state.flowing = true;
834-
flow(src);
833+
src.resume();
835834
}
836835
};
837836
}
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.