Skip to content

fix(gateway): verify process is alive after restart before reporting success - #325

Open
sridhar-3009 wants to merge 1 commit into
HKUDS:mainfrom
sridhar-3009:fix/301-gateway-restart-verification
Open

fix(gateway): verify process is alive after restart before reporting success#325
sridhar-3009 wants to merge 1 commit into
HKUDS:mainfrom
sridhar-3009:fix/301-gateway-restart-verification

Conversation

@sridhar-3009

Copy link
Copy Markdown

Summary

Closes #301

ohmo gateway restart called start_gateway_process() and immediately
printed "restarted (pid=N)" — no verification that the subprocess was
still alive. If the gateway crashed on startup (bad config, port
conflict, missing dependency), the command silently reported success
while the service stayed down, requiring a manual container restart.

Root cause in start_gateway_process:

  • stdout/stderr are redirected to gateway.log so no output
    appears in the calling terminal.
  • subprocess.Popen returns a handle instantly; the PID is returned
    immediately without checking whether the process survived.

Fix: After spawning, poll _pid_is_running(process.pid) for up to
~1.5 s in increasing intervals (0.1 s → 0.2 s → 0.4 s → 0.8 s).
This gives the process enough time to initialise before declaring it
healthy, while still catching immediate crashes. If no poll succeeds,
raise RuntimeError with the PID and log file path.

Update gateway_restart_cmd and _maybe_restart_gateway to catch that
error and surface a clear message (non-zero exit for the CLI command).

Test plan

  • Start gateway normally — verify ohmo gateway restart still prints restarted (pid=N) and the service is up.
  • Simulate a startup failure (e.g. invalid gateway config) — verify restart now prints an error pointing to the log file instead of falsely reporting success.
  • Verify gateway start (not modified) still works unchanged.

…success

gateway_restart_cmd (and the config-change restart helper) called
start_gateway_process and immediately printed "restarted (pid=N)" with
no check that the subprocess actually stayed running. If the gateway
crashed on startup (e.g. bad config, missing dependency), the command
silently reported success while the service stayed down, requiring a
manual container restart to recover.

Add a short polling loop in start_gateway_process that checks
_pid_is_running() up to ~1.5 s after spawn. If the process has already
exited by then, raise RuntimeError with the PID and log path so the
caller can surface a clear error. Update gateway_restart_cmd and
_maybe_restart_gateway to catch this error and report it rather than
pretending the restart succeeded.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ohmo gateway restart 停止后无法自动重启

1 participant