Skip to content

process: expose enhanced stack trace to uncaughtException handlers - #65580

Open
santusht06 wants to merge 1 commit into
nodejs:mainfrom
santusht06:fix-uncaught-exception-enhanced-stack
Open

process: expose enhanced stack trace to uncaughtException handlers#65580
santusht06 wants to merge 1 commit into
nodejs:mainfrom
santusht06:fix-uncaught-exception-enhanced-stack

Conversation

@santusht06

Copy link
Copy Markdown

When an EventEmitter instance emits an unhandled 'error' event, Node attaches an internal stack enhancer (kEnhanceStackBeforeInspector) capturing the call site where emit('error', ...) was invoked.

However, createOnGlobalUncaughtException() in lib/internal/process/execution.js was dispatching the error to uncaughtExceptionMonitor and uncaughtException listeners before executing fatalExceptionStackEnhancers.beforeInspector(er).

As a result, custom uncaught exception handlers and APM monitoring libraries were unable to access the enhanced call site on err.stack.

Changes

  • Invoked fatalExceptionStackEnhancers.beforeInspector(er) in createOnGlobalUncaughtException() prior to emitting uncaughtExceptionMonitor and uncaughtException.
  • Added test/parallel/test-process-uncaught-exception-enhanced-stack.js to verify that both uncaughtExceptionMonitor and uncaughtException receive the enhanced err.stack containing the emit('error', ...) call site for EventEmitter and subclass instances.

Fixes: #55838

When an EventEmitter instance emits an unhandled 'error' event, Node
attaches an internal stack enhancer (`kEnhanceStackBeforeInspector`)
capturing the call site of the `emit('error', ...)` invocation.

However, `createOnGlobalUncaughtException()` was dispatching the error
to `uncaughtExceptionMonitor` and `uncaughtException` listeners before
running `fatalExceptionStackEnhancers.beforeInspector(er)`.

As a result, custom uncaught exception handlers and monitoring
libraries did not receive the enhanced call site on `err.stack`.

This commit runs `fatalExceptionStackEnhancers.beforeInspector(er)`
before emitting `uncaughtExceptionMonitor` and `uncaughtException`,
ensuring the full emitter call site is accessible to handlers.

Fixes: nodejs#55838
Signed-off-by: Santusht kotai <115890693+santusht06@users.noreply.github.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose the "enhanced" stack trace from uncaught exceptions to the uncaughtException and uncaughtExceptionMonitor handlers on process

2 participants