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 <[email protected]>
Reviewed-By: Robert Nagy <[email protected]>
  • Loading branch information
jakecastelli committed Aug 5, 2024
1 parent a816688 commit fafc845
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 @@ -214,7 +214,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 fafc845

Please sign in to comment.