Skip to content

Commit fab8c83

Browse files
ronagMylesBorins
authored andcommitted
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. Backport-PR-URL: #32212 PR-URL: #32198 Refs: 4d93e10#commitcomment-37751035 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 66fe2d9 commit fab8c83

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/internal/streams/pipeline.js

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ function destroyer(stream, reading, writing, final, callback) {
5757
return callback();
5858
}
5959

60+
if (!err && reading && !writing && stream.writable) {
61+
return callback();
62+
}
63+
6064
if (err || !final || !stream.readable) {
6165
destroyImpl.destroyer(stream, err);
6266
}

test/parallel/test-stream-pipeline.js

+16
Original file line numberDiff line numberDiff line change
@@ -1016,3 +1016,19 @@ const { promisify } = require('util');
10161016
req.on('error', common.mustNotCall());
10171017
});
10181018
}
1019+
1020+
{
1021+
// Might still want to be able to use the writable side
1022+
// of src. This is in the case where e.g. the Duplex input
1023+
// is not directly connected to its output. Such a case could
1024+
// happen when the Duplex is reading from a socket and then echos
1025+
// the data back on the same socket.
1026+
const src = new PassThrough();
1027+
assert.strictEqual(src.writable, true);
1028+
const dst = new PassThrough();
1029+
pipeline(src, dst, common.mustCall((err) => {
1030+
assert.strictEqual(src.writable, true);
1031+
assert.strictEqual(src.destroyed, false);
1032+
}));
1033+
src.push(null);
1034+
}

0 commit comments

Comments
 (0)