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();