stream: fix premature pipeline end
Fixes: https://github.com/nodejs/node/issues/48406 PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
578ffe1edb
commit
cebbc57ed2
@ -38,7 +38,7 @@ const {
|
||||
isTransformStream,
|
||||
isWebStream,
|
||||
isReadableStream,
|
||||
isReadableEnded,
|
||||
isReadableFinished,
|
||||
} = require('internal/streams/utils');
|
||||
const { AbortController } = require('internal/abort_controller');
|
||||
|
||||
@ -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);
|
||||
|
@ -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);
|
||||
}));
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user