Skip to content

fix(gateway): recover from stale PID file after SIGKILL/OOM - #29349

Closed
Tranquil-Flow wants to merge 1 commit into
NousResearch:mainfrom
Tranquil-Flow:fix/13655-stale-gateway-pid
Closed

fix(gateway): recover from stale PID file after SIGKILL/OOM#29349
Tranquil-Flow wants to merge 1 commit into
NousResearch:mainfrom
Tranquil-Flow:fix/13655-stale-gateway-pid

Conversation

@Tranquil-Flow

@Tranquil-Flow Tranquil-Flow commented May 20, 2026

Copy link
Copy Markdown
Contributor

Closing in favor of #25569 (by @zccyman) which fixes the stale PID issue at the source inside itself, rather than in the caller's FileExistsError handler.

Comparison:

Both approaches preserve atomic O_CREAT|O_EXCL semantics for genuine concurrent races. #25569's approach is preferable because it makes self-healing for all callers, not just .

Thanks to alt-glitch for flagging the competing PRs (#25569, #9703, #14609).

…ousResearch#13655)

After a SIGKILL or OOM kill, atexit handlers never fire and gateway.pid
is left behind with a dead PID.  The next startup hits FileExistsError
from the O_CREAT|O_EXCL write and exits with 'PID file race lost',
even though no other gateway is running.

The FileExistsError handler now reads the existing PID file and checks
whether the recorded process is still alive.  If the PID is stale, the
file is force-unlinked and the write is retried.  Only if the PID is
confirmed alive (or a second race is lost) does the gateway exit.

Tests: 12 new tests covering record parsing, stale detection, recovery,
and double-race scenarios.
@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery P1 High — major feature broken, no workaround labels May 20, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Seventh attempt at fixing stale PID recovery (#13655). Related open PRs: #25569 (stale PID cleanup before O_EXCL write), #9703 (systemd ExecStartPre cleanup), #14609 (stale PID + httpx client eviction). Prior closed attempts: #13934, #13709, #13872, #13947, #14002, #14298, #14388.

@Tranquil-Flow

Copy link
Copy Markdown
Contributor Author

Closing in favor of #25569 (by @zccyman) which fixes the stale PID issue at the source inside itself, rather than in the caller's FileExistsError handler.

Comparison:

Both approaches preserve atomic O_CREAT|O_EXCL semantics for genuine concurrent races. #25569's approach is preferable because it makes write_pid_file() self-healing for all callers, not just start_gateway().

Thanks to alt-glitch for flagging the competing PRs (#25569, #9703, #14609).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P1 High — major feature broken, no workaround type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants