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 <noreply@anthropic.com>
This commit is contained in:
jeffr
2026-02-21 23:15:43 -08:00
committed by Peter Steinberger
parent 01bd83d644
commit 9c30243c8f

View File

@@ -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 {