Skip to content

Commit 337cd41

Browse files
jakecastellitargos
authored andcommittedOct 2, 2024
stream: make checking pendingcb on WritableStream backward compatible
PR-URL: #54142 Fixes: #54131 Refs: #54131 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com>
1 parent 8fd951f commit 337cd41

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed
 

‎lib/internal/streams/end-of-stream.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function eos(stream, options, callback) {
215215
!readable &&
216216
(!willEmitClose || isReadable(stream)) &&
217217
(writableFinished || isWritable(stream) === false) &&
218-
(wState == null || wState.pendingcb === 0)
218+
(wState == null || wState.pendingcb === undefined || wState.pendingcb === 0)
219219
) {
220220
process.nextTick(onclosed);
221221
} else if (

‎test/parallel/test-stream-finished.js

+13
Original file line numberDiff line numberDiff line change
@@ -687,3 +687,16 @@ testClosed((opts) => new Writable({ write() {}, ...opts }));
687687
assert.strictEqual(stream._writableState.pendingcb, 0);
688688
}));
689689
}
690+
691+
{
692+
const stream = new Duplex({
693+
write(chunk, enc, cb) {}
694+
});
695+
696+
stream.end('foo');
697+
698+
// Simulate an old stream implementation that doesn't have pendingcb
699+
delete stream._writableState.pendingcb;
700+
701+
finished(stream, { readable: false }, common.mustCall());
702+
}

0 commit comments

Comments
 (0)
Please sign in to comment.