Repository navigation
[async_hooks] Wrong after callback in case of uncaughtException #22982
Description
Activity
I think the issue might be that we manually kick off
nextTickfromModule.runMain(), i.e. after running the main script, but while still on the main script stack. For other invocations, we only run the nextTick queue after returning to C++ from whatever callback we invoked, including forsetTimeouts… does that make sense?- addedasync_hooksIssues and PRs related to the async hooks subsystem.Issues and PRs related to the async hooks subsystem.
on Sep 22, 2018 So, a few issues involved here:
- When do the
emitAfterloop in_fatalException, we need to ignore async frames with ID of 0. - There's already a stack for nextTick upon the start of the program, as @addaleax mentioned above which leads it to the
1being logged. This is technically not a bug but it could be confusing... I don't really have an opinion as to whether it should be fixed... maybe?
- When do the
For completeness the results with other node versions:
Master setTimeoutTimeout(5): trigger: 1 execution: 1 before: 5 in callback uncaughtException Immediate(6): trigger: 5 execution: 5 after: 5 after: 0 destroy: 5 before: 6 after: 6 destroy: 610.11.0 setTimeout:
Timeout(5): trigger: 1 execution: 1 TIMERWRAP(6): trigger: 1 execution: 1 before: 6 before: 5 in callback uncaughtException Immediate(7): trigger: 5 execution: 5 after: 5 after: 6 before: 6 <== strange before/after 6 again here with no callback inbetween after: 6 destroy: 5 before: 7 after: 7 destroy: 7 destroy: 68.12.0 setTimeout:
Timeout(5): trigger: 1 execution: 1 TIMERWRAP(6): trigger: 1 execution: 1 before: 6 before: 5 in callback uncaughtException Immediate(7): trigger: 5 execution: 5 after: 5 after: 6 destroy: 5 before: 7 after: 7 destroy: 7 destroy: 6I think we should not signal
afterif there was nobeforesignalled.I'm not sure about the 0/1 entries. If there are present because "something" / "the system" is running we should not remove them. But is there any need to have them on stack at all? Why not default to 0/1 if there is nothing on stack?
The issue with
nextTickseems to be solved since 13.2.0. I guess it was one of the commits from @addaleax done around 6.11.
setTimeouthas not changed.- 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 - added a commit that references this issue
on Jan 25, 2022 - added a commit that references this issue
on Feb 26, 2022 - added a commit that references this issue
on Mar 14, 2022 - added a commit that references this issue
on May 22, 2026
async_hooks call
afterwith wrong id if an uncaughtException happens which does not end the process.Results in
if I change the sample above to use
setTimeoutinsteadprocess.nextTickthe issue is limited to master and theasync_idemitted is 0 instead 1.I tried to find the root cause and I thought it's in
_fatalExceptionwhich should emitafterfor all except the last ids and in case there are no hooks clear all except the last.But if I check the working
setTimeoutcase in NodeJs 8.12.0 the stack only holds the async_ids for Timeout and TIMERWRAP but not the 0/1 entries.