process: expose enhanced stack trace to uncaughtException handlers - #65580
process: expose enhanced stack trace to uncaughtException handlers#65580santusht06 wants to merge 1 commit into
Conversation
|
Review requested:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #65580 +/- ##
==========================================
+ Coverage 90.18% 90.19% +0.01%
==========================================
Files 771 771
Lines 264619 264640 +21
Branches 50231 50238 +7
==========================================
+ Hits 238653 238701 +48
+ Misses 16961 16947 -14
+ Partials 9005 8992 -13
🚀 New features to boost your workflow:
|
This comment was marked as resolved.
This comment was marked as resolved.
|
Thank you @MikeMcC399. I have closed #65531 and #65543 to focus solely on this PR. I will fix the CI failures and run the full test suite before pushing any further updates. Apologies for not following the one-PR-at-a-time guideline. |
|
Rebased onto the latest |
|
Converting to draft. After deeper analysis I found a critical bug in the current approach:
Need to design this more carefully before proceeding. |
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.
Previously, `createOnGlobalUncaughtException()` dispatched the error
to `uncaughtExceptionMonitor` and `uncaughtException` listeners before
applying this enhancement. Consequently, user handlers and monitoring
libraries did not see the emitter call site on `err.stack`.
This commit enhances the stack trace directly via the internal
`kEnhanceStackBeforeInspector` symbol before invoking user handlers,
and removes the symbol so the C++ fatal exception exit path does not
double-apply the frame if the exception remains unhandled.
Also update `test-events-uncaught-exception-stack.js` to assert the
enhanced frame is present, and add a comprehensive test suite covering
monitor listeners, subclass emitters, and fatal double-call safety.
Fixes: nodejs#55838
Signed-off-by: Santusht kotai <115890693+santusht06@users.noreply.github.com>
Assisted-by: Antigravity
ed6bd63 to
9e69cf3
Compare
When an
EventEmitterinstance emits an unhandled'error'event, Node attaches an internal stack enhancer (kEnhanceStackBeforeInspector) capturing the call site whereemit('error', ...)was invoked.However,
createOnGlobalUncaughtException()inlib/internal/process/execution.jswas dispatching the error touncaughtExceptionMonitoranduncaughtExceptionlisteners before executingfatalExceptionStackEnhancers.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
fatalExceptionStackEnhancers.beforeInspector(er)increateOnGlobalUncaughtException()prior to emittinguncaughtExceptionMonitoranduncaughtException.test/parallel/test-process-uncaught-exception-enhanced-stack.jsto verify that bothuncaughtExceptionMonitoranduncaughtExceptionreceive the enhancederr.stackcontaining theemit('error', ...)call site forEventEmitterand subclass instances.Fixes: #55838