Repository navigation
lib: callbacks firing twice if first attempt throws #58419
Description
Activity
What happens with the exception when it's no longer caught but bubbles upwards instead? It's important that it doesn't just disappear into the void.
@bnoordhuis I don't think the errors will go unnoticed. I shared a piece of code included in the patch: https://github.com/0hmX/node/blob/2fdc8ee07ff51c532162bc34614251cbcbd1ee43/lib/internal/fs/dir.js#L148-L158
We simply check if an error has already occurred; if so, we call the callback with the error; otherwise, we make a regular success callback.
What happens with the exception when it's no longer caught but bubbles upwards instead?
If an exception happens in the callback and is not caught inside the callback, it should bubble up and crash the program (unless something like
process.on('uncaughtException')or evendomainintercepts it), just like any other unhandled error.I agree that's what should happen but it's important to check (not assume) it really happens.
- added a commit that references this issue
on Jun 17, 2025 github-actions commented
on Apr 19, 2026 on Apr 19, 2026 – with GitHub ActionsContributorMore actionsThis issue has been marked as stale due to 210 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.- addedstaleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
on Apr 19, 2026 github-actions commented
on May 20, 2026 on May 20, 2026 – with GitHub ActionsContributorMore actionsThis issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 240 days).
If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.
There are a few places where code flows like this:
These are usually (if not always) bugs, because it wraps the
callbackcall itself in thetryblock, and if that callback throws, it gets caught and called again, but this time with its ownerror.For example:
node/lib/internal/fs/dir.js
Lines 150 to 160 in 06fb007
node/lib/internal/streams/compose.js
Lines 153 to 161 in 06fb007
Some of these bugs might be a good first issueIssues that are suitable for first-time contributors.
candidates.