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 {