From 9c30243c8f6e24a1350303c6e9cd45441cfcc208 Mon Sep 17 00:00:00 2001 From: jeffr Date: Sat, 21 Feb 2026 23:15:43 -0800 Subject: [PATCH] fix: release gateway lock before spawning restart child Move lock.release() before restartGatewayProcessWithFreshPid() so the spawned child can immediately acquire the lock without racing against a zombie parent. This eliminates the root cause of the restart loop where the child times out waiting for a lock held by its now-dead parent. Co-Authored-By: Claude Opus 4.6 --- src/cli/gateway-cli/run-loop.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cli/gateway-cli/run-loop.ts b/src/cli/gateway-cli/run-loop.ts index d890047cf02..a4601743164 100644 --- a/src/cli/gateway-cli/run-loop.ts +++ b/src/cli/gateway-cli/run-loop.ts @@ -83,6 +83,8 @@ export async function runGatewayLoop(params: { clearTimeout(forceExitTimer); server = null; if (isRestart) { + // Release the lock BEFORE spawning so the child can acquire it immediately. + await lock?.release(); const respawn = restartGatewayProcessWithFreshPid(); if (respawn.mode === "spawned" || respawn.mode === "supervised") { const modeLabel = @@ -90,7 +92,6 @@ export async function runGatewayLoop(params: { ? `spawned pid ${respawn.pid ?? "unknown"}` : "supervisor restart"; gatewayLog.info(`restart mode: full process restart (${modeLabel})`); - await lock?.release(); cleanupSignals(); params.runtime.exit(0); } else {