Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: callback should be called when pendingcb is 0 #53438

Merged
merged 5 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/internal/streams/end-of-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ function eos(stream, options, callback) {
} else if (
!readable &&
(!willEmitClose || isReadable(stream)) &&
(writableFinished || isWritable(stream) === false)
(writableFinished || isWritable(stream) === false) &&
wState && wState.pendingcb === 0
jakecastelli marked this conversation as resolved.
Show resolved Hide resolved
) {
process.nextTick(onclosed);
} else if (
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-stream-finished.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,5 +679,6 @@ testClosed((opts) => new Writable({ write() {}, ...opts }));

finished(stream, { readable: false }, common.mustCall((err) => {
assert(!err);
assert.strictEqual(stream._writableState.pendingcb, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test that does not look into _writableState? Why are you doing this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, I will add a new test to address it, thanks!

Why are you doing this change?

Do you mean the change to the test? If so, it is because when the callback function is called in stream.finished it won't wait for the callback in the writable._write (if any async action is performed) and one of the indication is stream._writableState.pendingcb is not 0.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have expanded the test to make sure the cb in _write is called before the cb in finished is called. PTAL @mcollina 🙏

}));
}