fix: hermes update kills freshly-restarted gateway service (salvage #5409) - #5448
Merged
Conversation
After restarting a service-managed gateway (systemd/launchd), the stale-process sweep calls find_gateway_pids() which returns ALL gateway PIDs via ps aux — including the one just spawned by the service manager. The sweep kills it, leaving the user with a stopped gateway and a confusing 'Restart manually' message. Fix: add _get_service_pids() to query systemd MainPID and launchd PID for active gateway services, then exclude those PIDs from the sweep. Also add exclude_pids parameter to find_gateway_pids() and kill_gateway_processes() so callers can skip known service-managed PIDs. Adds 9 targeted tests covering: - _get_service_pids() for systemd, launchd, empty, and zero-PID cases - find_gateway_pids() exclude_pids filtering - cmd_update integration: service PID not killed after restart - cmd_update integration: manual PID killed while service PID preserved
…f-import, harden launchd parsing - Loop over user/system scope args instead of duplicating the systemd block - Call get_launchd_label() directly instead of self-importing from hermes_cli.gateway - Validate launchd output by checking parts[2] matches expected label (skip header) - Add race-condition assumption docstring
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
Salvage of #5409 by @kshitijk4poor onto current main.
After
hermes update, the gateway service restarts via systemd/launchd, thenfind_gateway_pids()sweeps for stale manual processes — but returns ALL matching PIDs, including the one just spawned by the service manager. The sweep kills it immediately.Fix
_get_service_pids()helper that queries systemdMainPIDand launchd PID for active gateway servicesexclude_pidsparameter tofind_gateway_pids()andkill_gateway_processes()cmd_update(), call_get_service_pids()and pass the result to exclude them from the sweepTests
9 new tests (29 total in file, all passing):
TestGetServicePids: systemd MainPID, launchd PID, empty, zero-PID exclusionTestFindGatewayPidsExclude: exclude_pids filteringTestServicePidExclusion: integration tests proving service PID survives after restart, manual PIDs still killedCherry-picked with contributor authorship preserved. Merged cleanly with recent #5424 (subprocess timeouts).