Skip to content
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
stream: fix premature pipeline end
Fixes: #48406
  • Loading branch information
ronag committed Jun 12, 2023
commit ab1b4dfb622eb9fc0261cbe421e69b84d9a65f93
4 changes: 2 additions & 2 deletions lib/internal/streams/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const {
isTransformStream,
isWebStream,
isReadableStream,
isReadableEnded,
isReadableFinished,
} = require('internal/streams/utils');
const { AbortController } = require('internal/abort_controller');

Expand Down Expand Up @@ -424,7 +424,7 @@ function pipe(src, dst, finish, { end }) {
dst.end();
}

if (isReadableEnded(src)) { // End the destination if the source has already ended.
if (isReadableFinished(src)) { // End the destination if the source has already ended.
process.nextTick(endFn);
} else {
src.once('end', endFn);
Expand Down
28 changes: 28 additions & 0 deletions test/parallel/test-stream-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -1634,3 +1634,31 @@ const tsp = require('timers/promises');
assert.strictEqual(writable.closed, false);
}));
}

{
const r = new Readable();
for (let i = 0; i < 4000; i++) {
r.push('asdfdagljanfgkaljdfn');
}
r.push(null);

let ended = false;
r.on('end', () => {
ended = true;
});

const w = new Writable({
write(chunk, enc, cb) {
cb(null);
},
final: common.mustCall((cb) => {
assert.strictEqual(ended, true);
cb(null);
})
});

pipeline(r, w, common.mustCall((err) => {
assert.strictEqual(err, undefined);
}));

Comment thread
ronag marked this conversation as resolved.
}