Skip to content

hermes gateway restart hangs on macOS due to KeepAlive race condition #5126

@darkworon

Description

@darkworon

Problem

hermes gateway restart hangs indefinitely on macOS when the gateway is managed by launchd with KeepAlive/SuccessfulExit = false.

Root cause

launchd_restart() in hermes_cli/gateway.py does:

  1. launchctl stop <label> — sends SIGTERM
  2. _wait_for_gateway_exit() — polls until the PID disappears
  3. launchctl start <label>

But with KeepAlive/SuccessfulExit = false, launchd immediately respawns the process after stop, so step 2 never completes — the old PID dies but a new one appears instantly.

Fix

Use launchctl kickstart -kp gui/<uid>/<label> which atomically kills and restarts the service in one operation, avoiding the race. Falls back to the old stop/wait/start sequence if kickstart fails (e.g., on older macOS).

Environment

  • macOS (tested on M4 Max, Sequoia)
  • launchd plist with KeepAlive/SuccessfulExit = false

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions