-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
2 changed files
with
45 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"use strict"; | ||
|
||
const common = require('../common'); | ||
const { Readable, Writable } = require('stream'); | ||
|
||
// https://github.com/nodejs/node/issues/48666 | ||
(async () => { | ||
// Prepare src that is internally ended, with buffered data pending | ||
const src = new Readable({ read() {} }); | ||
src.push(Buffer.alloc(100)); | ||
src.push(null); | ||
src.pause(); | ||
|
||
// Give it time to settle | ||
await new Promise((resolve) => setImmediate(resolve)); | ||
|
||
const dst = new Writable({ | ||
highWaterMark: 1000, | ||
write(buf, enc, cb) { | ||
process.nextTick(cb); | ||
} | ||
}); | ||
|
||
dst.write(Buffer.alloc(1000)); // Fill write buffer | ||
dst.on('finish', common.mustCall()); | ||
src.pipe(dst); | ||
})(); |