src/node_errors: add re-entrancy guard to TriggerUncaughtException#64327
Open
themuuln wants to merge 1 commit into
Open
src/node_errors: add re-entrancy guard to TriggerUncaughtException#64327themuuln wants to merge 1 commit into
themuuln wants to merge 1 commit into
Conversation
β¦in TriggerUncaughtException Add a thread_local re-entrancy guard to TriggerUncaughtException() that detects when the JS-level exception handler (process._fatalException) itself triggers another exception through the inspector protocol. This prevents the infinite loop: TriggerUncaughtException -> InspectorConsoleCall -> TriggerUncaughtException -> InspectorConsoleCall -> ... When re-entrancy is detected, the function prints a diagnostic with the formatted exception to stderr using FormatCaughtException (which avoids the inspector path entirely), then aborts the process. Fixes: nodejs#64326
d6df9be to
955d7e4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When an uncaught exception triggers
TriggerUncaughtExceptionβ the JS handler (process._fatalException) βconsole.errorβ the inspector protocol (InspectorConsoleCall) throws again, V8 re-entersTriggerUncaughtException. This creates a tight infinite loop:Each iteration:
This was observed in production with napi-rs plugins calling
console.errorduring uncaught exception handling, but any JS handler that triggers inspector protocol activity duringprocess._fatalExceptioncan hit it.Fix
Add a
thread_localre-entrancy guard toTriggerUncaughtException(). If the function is re-entered while already processing an uncaught exception, it:FormatCaughtException(pure V8 string ops β no JS, no inspector)PrintToStderrAndFlushABORT()to terminate the processAn RAII scope guard resets the flag when
TriggerUncaughtExceptionreturns normally (e.g.,env->Exit()path).The guard lives entirely in
node_errors.ccβ no header changes, noEnvironmentfields.Fixes: #64326