Repository navigation
error handler of same domain can be called several times when it throws #25505
Description
Activity
- addeddomainIssues and PRs related to the domain subsystem.Issues and PRs related to the domain subsystem.
on Jan 15, 2019 - addedhelp wantedIssues that need assistance from volunteers or PRs that need help to proceed.Issues that need assistance from volunteers or PRs that need help to proceed.
on Jun 26, 2020 i would like to work on this issue, thank you
Hey! I'm fairly new to open source but have a few years of industry experience under my belt. Is this issue still open and unassigned? I'd love to take a shot at it and submit a PR!
I tried reproducing this on current Node.js main / v27.0.0-pre and 26.3.0, and I don’t seem to be able to reproduce the issue anymore.
Using the code from the issue, I now get:
1 /path/to/test.js:30 throw new Error('boom'); ^ Error: boom at Domain.<anonymous> (/path/to/test.js:30:11) at Domain.emit (node:events:509:20) at Domain.emit (node:domain:473:12) at Domain._errorHandler (node:domain:263:23) at Object.<anonymous> (node:domain:165:29) at process._fatalException (node:internal/process/execution:179:29)I do not see the previous behavior where the handler was called twice and printed both 1 and 2.
From my understanding, that is the original bang error should be handled by the domain, but an error thrown from that domain’s own error handler should not re-enter the same handler.
I might be missing something, but I think this issue may be fixed now. Can someone check and maybe close this issue?
github-actions commented
on Sep 26, 2026 on Sep 26, 2026 – with GitHub ActionsContributorMore actionsThis issue has been marked as stale due to 90 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 Sep 26, 2026
The following code:
gives the following output:
The uncaught exception is expected. What is not expected as far as I understand is for the same domain's error handler to run more than once.
I believe the original intention of the domain's implementation is to pop the domains stack when a domain's error handler throw, so that the domain that handles that new error is the "parent" domain.
However, in the example above the same domain is pushed on the stack more than once. For instance, when an event is emitted from a nextTick callback, the same domain will be entered from the nextTick callbacks scheduler and then once again from the event emitter.
Pushing the same domain on the stack more than once makes sense so that the components that push a domain can pop it from the stack. However, I think we could probably replace the call to pop the stack once in the domain error handling code to remove all consecutive instances of that domain instead.
@nodejs/domains Thoughts?