fix: recover from stale PID file on gateway startup#14388
Closed
eLeanwang wants to merge 1 commit into
Closed
Conversation
When a gateway process is killed by SIGKILL (e.g. systemd TimeoutStopSec exceeded, OOM killer), atexit handlers never run and the PID file is left behind. On the next startup, write_pid_file() hits FileExistsError and logs "PID file race lost", causing systemd to exhaust its restart burst (StartLimitBurst=5) and leave the gateway in a failed state requiring manual intervention. Fix: when write_pid_file() raises FileExistsError, call get_running_pid(cleanup_stale=True) to check whether the recorded PID is still alive. If the process is gone, the stale file is cleaned up automatically and write_pid_file() is retried once. A genuine race (live competing instance) still fails immediately.
Collaborator
Collaborator
|
Competing fix for #13655. |
Contributor
|
Thanks for the contribution, @eLeanwang! This stale-PID restart loop was fixed on This is an automated hermes-sweeper review. Evidence:
The original bug report is tracked in #13655. Related open PRs #13709 and #9703 address the same issue and may also be closeable now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When killed by SIGKILL (systemd timeout, OOM), atexit handlers don't run and gateway.pid persists. On next startup, write_pid_file() hits FileExistsError and logs 'PID file race lost', causing systemd to exhaust restart attempts.
Fix: on FileExistsError, check if the recorded PID is alive via get_running_pid(cleanup_stale=True). If dead, clean up the stale file and retry write_pid_file() once. Genuine races (live competing instance) still fail immediately.