mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
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: https://github.com/nodejs/node/issues/48666 PR-URL: https://github.com/nodejs/node/pull/48691 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
1 parent
69b55d2261
commit
daeb21dde9
2 files changed
+28
-3
No files matched your search
@@ -833,9 +833,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
|
||||
// Start the flow if it hasn't been started already.
|
||||
|
||||
if (dest.writableNeedDrain === true) {
|
||||
if (state.flowing) {
|
||||
pause();
|
||||
}
|
||||
pause();
|
||||
} else if (!state.flowing) {
|
||||
debug('pipe resume');
|
||||
src.resume();
|
||||
|
||||
@@ -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);
|
||||
})().then(common.mustCall());
|
||||
Reference in new issue
Block a user