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

[v13.x backport] stream: avoid destroying writable source #32211

Closed
Closed
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
5 changes: 5 additions & 0 deletions lib/internal/streams/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ function destroyer(stream, reading, writing, final, callback) {
eos(stream, { readable: reading, writable: writing }, (err) => {
if (destroyed) return;
destroyed = true;

if (!err && reading && !writing && stream.writable) {
return callback();
}

const readable = stream.readable || isRequest(stream);
if (err || !final || !readable) {
destroyImpl.destroyer(stream, err);
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-stream-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -995,3 +995,19 @@ const { promisify } = require('util');
assert.strictEqual(res, '');
}));
}

{
// Might still want to be able to use the writable side
// of src. This is in the case where e.g. the Duplex input
// is not directly connected to its output. Such a case could
// happen when the Duplex is reading from a socket and then echos
// the data back on the same socket.
const src = new PassThrough();
assert.strictEqual(src.writable, true);
const dst = new PassThrough();
pipeline(src, dst, common.mustCall((err) => {
assert.strictEqual(src.writable, true);
assert.strictEqual(src.destroyed, false);
}));
src.push(null);
}