Skip to content

Commit 84d0eb7

Browse files
ronagRafaelGSS
authored andcommitted
stream: fix premature pipeline end
Fixes: #48406 PR-URL: #48435 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Debadree Chatterjee <debadree333@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 32bda81 commit 84d0eb7

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

lib/internal/streams/pipeline.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const {
3838
isTransformStream,
3939
isWebStream,
4040
isReadableStream,
41-
isReadableEnded,
41+
isReadableFinished,
4242
} = require('internal/streams/utils');
4343
const { AbortController } = require('internal/abort_controller');
4444

@@ -424,7 +424,7 @@ function pipe(src, dst, finish, { end }) {
424424
dst.end();
425425
}
426426

427-
if (isReadableEnded(src)) { // End the destination if the source has already ended.
427+
if (isReadableFinished(src)) { // End the destination if the source has already ended.
428428
process.nextTick(endFn);
429429
} else {
430430
src.once('end', endFn);

test/parallel/test-stream-pipeline.js

+28
Original file line numberDiff line numberDiff line change
@@ -1634,3 +1634,31 @@ const tsp = require('timers/promises');
16341634
assert.strictEqual(writable.closed, false);
16351635
}));
16361636
}
1637+
1638+
{
1639+
const r = new Readable();
1640+
for (let i = 0; i < 4000; i++) {
1641+
r.push('asdfdagljanfgkaljdfn');
1642+
}
1643+
r.push(null);
1644+
1645+
let ended = false;
1646+
r.on('end', () => {
1647+
ended = true;
1648+
});
1649+
1650+
const w = new Writable({
1651+
write(chunk, enc, cb) {
1652+
cb(null);
1653+
},
1654+
final: common.mustCall((cb) => {
1655+
assert.strictEqual(ended, true);
1656+
cb(null);
1657+
})
1658+
});
1659+
1660+
pipeline(r, w, common.mustCall((err) => {
1661+
assert.strictEqual(err, undefined);
1662+
}));
1663+
1664+
}

0 commit comments

Comments
 (0)