Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: fix deadlock when pipeing to full sink #48691

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/internal/streams/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -822,9 +822,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();
ronag marked this conversation as resolved.
Show resolved Hide resolved
} else if (!state.flowing) {
debug('pipe resume');
src.resume();
Expand Down
27 changes: 27 additions & 0 deletions test/parallel/test-stream-pipe-deadlock.js
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);
})().then(common.mustCall());