Skip to content
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
stream: avoid destroying writable source
User 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.

Fixes: 4d93e10#commitcomment-37751035

Backport-PR-URL: #32211
  • Loading branch information
ronag committed Mar 11, 2020
commit a0f3d2b71880f0cb91aba3b0e1965219f2067598
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);
}