fix(gateway): clear stale pid file before service start#9703
Closed
john-livingston wants to merge 1 commit into
Closed
fix(gateway): clear stale pid file before service start#9703john-livingston wants to merge 1 commit into
john-livingston wants to merge 1 commit into
Conversation
This was referenced Apr 21, 2026
c2c8bfa to
9bbfe74
Compare
Contributor
|
Thanks for this careful fix, @john-livingston! The underlying stale-PID-on-abrupt-kill problem has since been addressed at a deeper layer on Automated hermes-sweeper review found this superseded by commit b52123e (
Closing as implemented on main. The cross-references to #7227 / #9574 (Windows stale PID) remain open for the Windows path. |
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.
Summary
When the gateway process is killed abruptly (SIGKILL, power loss, OOM)
it cannot clean up
gateway.pid. On the nextsystemctl start, thePID file is still present. If the old PID has been recycled by the OS,
get_running_pid()may incorrectly treat the new process as a runninggateway, blocking startup. If it correctly identifies the PID as stale,
startup proceeds but the file is left as noise until Python cleans it up.
Fix: Add
ExecStartPre=-/bin/rm -f {hermes_home}/gateway.pidtoboth service templates (user-level and system-level) in
generate_systemd_unit(). The-prefix makes the step non-fatal —if the file doesn't exist or the command fails for any reason, systemd
continues. The path is the Python f-string value of
hermes_home, bakedin at install time, so it targets the correct profile directory.
This is a belt-and-suspenders complement to
--replace:--replacehandles live processes via Python;
ExecStartPrehandles the stale-filecase at the OS level before Python starts.
Changes
hermes_cli/gateway.py— bothgenerate_systemd_unit()templates:insert
ExecStartPre=-/bin/rm -f {hermes_home}/gateway.pidbeforeExecStartRelated
gateway.pidcrash on Windows (same root cause,different platform; this fix addresses the Linux systemd path)
Test plan
gateway.pidleft by a killed processavailable in this environment)