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
10 changes: 9 additions & 1 deletion lib/internal/streams/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const {
isIterable,
isReadableNodeStream,
isNodeStream,
isReadableFinished,
} = require('internal/streams/utils');
const { AbortController } = require('internal/abort_controller');

Expand Down Expand Up @@ -229,7 +230,14 @@ function pipelineImpl(streams, callback, opts) {

if (isNodeStream(stream)) {
finishCount++;
destroys.push(destroyer(stream, reading, writing, finish));
destroys.push(destroyer(stream, reading, writing, (err) => {
if (!err && !reading && isReadableFinished(stream, false)) {
stream.read(0);
destroyer(stream, true, writing, finish);
} else {
finish(err);
}
}));
}

if (i === 0) {
Expand Down
22 changes: 21 additions & 1 deletion test/parallel/test-stream-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ const tsp = require('timers/promises');
const src = new PassThrough();
const dst = new PassThrough();
pipeline(src, dst, common.mustSucceed(() => {
assert.strictEqual(dst.destroyed, false);
assert.strictEqual(dst.destroyed, true);
}));
src.end();
}
Expand Down Expand Up @@ -1447,3 +1447,23 @@ const tsp = require('timers/promises');
assert.strictEqual(text, 'Hello World!');
}));
}

{
const pipelinePromise = promisify(pipeline);

async function run() {
const read = new Readable({
read() {}
});

const duplex = new PassThrough();

read.push(null);

await pipelinePromise(read, duplex);

assert.strictEqual(duplex.destroyed, true);
}

run();
}