Skip to content

Commit

Permalink
stream: make checking pendingcb on WritableStream backward compatible
Browse files Browse the repository at this point in the history
PR-URL: #54142
Fixes: #54131
Refs: #54131
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
  • Loading branch information
jakecastelli authored and targos committed Oct 2, 2024
1 parent 8fd951f commit 337cd41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/streams/end-of-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function eos(stream, options, callback) {
!readable &&
(!willEmitClose || isReadable(stream)) &&
(writableFinished || isWritable(stream) === false) &&
(wState == null || wState.pendingcb === 0)
(wState == null || wState.pendingcb === undefined || wState.pendingcb === 0)
) {
process.nextTick(onclosed);
} else if (
Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-stream-finished.js
Original file line number Diff line number Diff line change
Expand Up @@ -687,3 +687,16 @@ testClosed((opts) => new Writable({ write() {}, ...opts }));
assert.strictEqual(stream._writableState.pendingcb, 0);
}));
}

{
const stream = new Duplex({
write(chunk, enc, cb) {}
});

stream.end('foo');

// Simulate an old stream implementation that doesn't have pendingcb
delete stream._writableState.pendingcb;

finished(stream, { readable: false }, common.mustCall());
}

0 comments on commit 337cd41

Please sign in to comment.