@@ -74,6 +74,14 @@ export interface MainProcessFailureObserverDeps {
7474
7575const FAILURE_DEDUPE_MS = 5_000
7676
77+ function experimentTrace ( line : string ) : void {
78+ const entry = `[fatal-trace pid=${ process . pid } ${ new Date ( ) . toISOString ( ) } ] ${ line } \n`
79+ process . stdout . write ( entry )
80+ try {
81+ appendFileSync ( '/tmp/sim-fatal-trace.log' , entry )
82+ } catch { }
83+ }
84+
7785/**
7886 * Records native child-process failures and gives a fatal main-process error a
7987 * single native recovery surface. Error text is deliberately excluded from
@@ -120,6 +128,11 @@ export function installMainProcessFailureObservers({
120128 name : 'main_unhandled_rejection' | 'main_uncaught_exception' ,
121129 value : unknown
122130 ) : void => {
131+ experimentTrace (
132+ `fatal ${ name } quitStarted=${ quitStarted } open=${ fatalRecoveryOpen } \n${
133+ value instanceof Error ? `${ value . name } : ${ value . message } \n${ value . stack } ` : String ( value )
134+ } `
135+ )
123136 if ( fatalRecoveryOpen ) return
124137 fatalRecoveryOpen = true
125138 events . record ( name , { valueType : value instanceof Error ? 'Error' : typeof value } )
@@ -165,6 +178,11 @@ export function installMainProcessFailureObservers({
165178 app . on ( 'child-process-gone' , onChildProcessGone )
166179 app . on ( 'before-quit' , onQuitStarted )
167180 app . on ( 'will-quit' , onQuitStarted )
181+ app . on ( 'before-quit' , ( ) => experimentTrace ( 'before-quit' ) )
182+ app . on ( 'will-quit' , ( ) => experimentTrace ( 'will-quit' ) )
183+ app . on ( 'quit' , ( ) => experimentTrace ( 'quit' ) )
184+ process . on ( 'exit' , ( ) => experimentTrace ( 'process exit' ) )
185+ experimentTrace ( 'observers installed' )
168186 processSource . on ( 'unhandledRejection' , onUnhandledRejection )
169187 processSource . on ( 'uncaughtException' , onUncaughtException )
170188}
0 commit comments