stream: callback should be called when pendingcb is 0

Fixes: https://github.com/nodejs/node/issues/46170
PR-URL: https://github.com/nodejs/node/pull/53438
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
jakecastelli authored and Marco Ippolito committed 2024-07-19 15:27:11 +02:00
1 parent 2aceed4297
commit 33a15be32f
2 files changed
+9 -2

No files matched your search

+2 -1
View File
@@ -214,7 +214,8 @@ function eos(stream, options, callback) {
} else if (
!readable &&
(!willEmitClose || isReadable(stream)) &&
(writableFinished || isWritable(stream) === false)
(writableFinished || isWritable(stream) === false) &&
(wState == null || wState.pendingcb === 0)
) {
process.nextTick(onclosed);
} else if (
+7 -1
View File
@@ -669,9 +669,13 @@ testClosed((opts) => new Writable({ write() {}, ...opts }));
}
{
let isCalled = false;
const stream = new Duplex({
write(chunk, enc, cb) {
setImmediate(cb);
setImmediate(() => {
isCalled = true;
cb();
});
}
});
@@ -679,5 +683,7 @@ testClosed((opts) => new Writable({ write() {}, ...opts }));
finished(stream, { readable: false }, common.mustCall((err) => {
assert(!err);
assert.strictEqual(isCalled, true);
assert.strictEqual(stream._writableState.pendingcb, 0);
}));
}