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 c224e1b

Browse filesBrowse files
ronagruyadorno
authored andcommitted
stream: fix deadlock when pipeing to full sink
When piping a paused Readable to a full Writable we didn't register a drain listener which cause the src to never resume. Refs: #48666 PR-URL: #48691 Backport-PR-URL: #49323 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 9d90409 commit c224e1b
Copy full SHA for c224e1b

File tree

Expand file treeCollapse file tree

2 files changed

+28
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+28
-3
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-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -814,9 +814,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
814814
// Start the flow if it hasn't been started already.
815815

816816
if (dest.writableNeedDrain === true) {
817-
if (state.flowing) {
818-
pause();
819-
}
817+
pause();
820818
} else if (!state.flowing) {
821819
debug('pipe resume');
822820
src.resume();
Collapse file
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const { Readable, Writable } = require('stream');
5+
6+
// https://github.com/nodejs/node/issues/48666
7+
(async () => {
8+
// Prepare src that is internally ended, with buffered data pending
9+
const src = new Readable({ read() {} });
10+
src.push(Buffer.alloc(100));
11+
src.push(null);
12+
src.pause();
13+
14+
// Give it time to settle
15+
await new Promise((resolve) => setImmediate(resolve));
16+
17+
const dst = new Writable({
18+
highWaterMark: 1000,
19+
write(buf, enc, cb) {
20+
process.nextTick(cb);
21+
}
22+
});
23+
24+
dst.write(Buffer.alloc(1000)); // Fill write buffer
25+
dst.on('finish', common.mustCall());
26+
src.pipe(dst);
27+
})().then(common.mustCall());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.