Skip to content

Commit 69455e9

Browse files
committed
fix(app-exit): send BEFORE_EXIT before tearing down trace; add [app-exit-diag] logs in app/app-index/app-prompt
1 parent af47b4e commit 69455e9

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/run/app-index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ process.title = `Kit Idle - Main Script`
4242
configEnv()
4343

4444
process.once("beforeExit", () => {
45-
send(Channel.BEFORE_EXIT)
45+
try {
46+
console.warn('[app-exit-diag] app-index BEFORE_EXIT sending')
47+
send(Channel.BEFORE_EXIT)
48+
} catch (e) {
49+
console.warn('[app-exit-diag] app-index send BEFORE_EXIT failed:', (e as any)?.message || e)
50+
}
4651
})
4752

4853
log(

src/run/app-prompt.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,22 @@ configEnv()
128128
process.title = `Kit - ${path.basename(script)}`
129129

130130
process.once('beforeExit', () => {
131-
if (global?.trace?.flush) {
132-
global.trace.flush()
133-
global.trace = null
131+
// Emit BEFORE_EXIT before tearing down tracing to avoid null deref
132+
try {
133+
console.warn('[app-exit-diag] app-prompt BEFORE_EXIT sending')
134+
send(Channel.BEFORE_EXIT)
135+
} catch (e) {
136+
console.warn('[app-exit-diag] send BEFORE_EXIT failed:', (e as any)?.message || e)
137+
}
138+
try {
139+
if (global?.trace?.flush) {
140+
global.trace.flush()
141+
}
142+
} catch (e) {
143+
console.warn('[app-exit-diag] trace.flush failed:', (e as any)?.message || e)
144+
} finally {
145+
try { (global as any).trace = null } catch {}
134146
}
135-
send(Channel.BEFORE_EXIT)
136147
})
137148

138149
performance.mark('run')

src/run/app.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ let script = await arg("Path to script:")
2424
process.title = path.basename(script)
2525

2626
process.once("beforeExit", () => {
27-
send(Channel.BEFORE_EXIT)
27+
try {
28+
console.warn('[app-exit-diag] app BEFORE_EXIT sending')
29+
send(Channel.BEFORE_EXIT)
30+
} catch (e) {
31+
console.warn('[app-exit-diag] app send BEFORE_EXIT failed:', (e as any)?.message || e)
32+
}
2833
})
2934

3035
await run(script)

0 commit comments

Comments
 (0)