From 94968c83c6d5b5087eedc087c7791f2735e56d36 Mon Sep 17 00:00:00 2001 From: Sebastien Tardif Date: Sat, 23 May 2026 20:40:34 -0700 Subject: [PATCH] fix(gmail-watcher): prevent TDZ in settleProcess and guard exit handler against stale child respawn --- src/hooks/gmail-watcher.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/hooks/gmail-watcher.ts b/src/hooks/gmail-watcher.ts index 66d9d382a3cc..9a9325beeae1 100644 --- a/src/hooks/gmail-watcher.ts +++ b/src/hooks/gmail-watcher.ts @@ -102,6 +102,10 @@ function spawnGogServe(cfg: GmailHookRuntimeConfig): ChildProcess { }); child.on("exit", (code, signal) => { + // If a newer watcher has replaced this child, do not respawn. + if (watcherProcess !== null && watcherProcess !== child) { + return; + } if (shuttingDown) { return; } @@ -134,6 +138,8 @@ function spawnGogServe(cfg: GmailHookRuntimeConfig): ChildProcess { function settleProcess(proc: ChildProcess): Promise { return new Promise((resolve) => { let settled = false; + let escalation: ReturnType | undefined; + let finalTimeout: ReturnType | undefined; const settle = () => { if (settled) { return; @@ -150,7 +156,7 @@ function settleProcess(proc: ChildProcess): Promise { proc.kill("SIGTERM"); - const escalation = setTimeout(() => { + escalation = setTimeout(() => { try { proc.kill("SIGKILL"); } catch { @@ -158,7 +164,7 @@ function settleProcess(proc: ChildProcess): Promise { } }, 3_000); - const finalTimeout = setTimeout(() => { + finalTimeout = setTimeout(() => { if (!settled) { log.warn("gog process did not exit after SIGKILL; giving up"); settle();