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 Aug 14, 2024
1 parent 4d8b53e commit 9297d29
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 9297d29

Please sign in to comment.