fix: clean stale gateway PIDs in triggerOpenClawRestart before launchctl/systemctl#27448
Merged
steipete merged 1 commit intoopenclaw:mainfrom Feb 26, 2026
Merged
Conversation
…nchctl/systemctl When the /restart command runs inside an embedded agent process (no SIGUSR1 listener), it falls through to triggerOpenClawRestart() which calls launchctl kickstart -k directly — bypassing the pre-restart port cleanup added in openclaw#27013. If the gateway was started via TUI/CLI, the orphaned process still holds the port and the new launchd instance crash-loops. Add synchronous stale-PID detection (lsof) and termination (SIGTERM→SIGKILL) inside triggerOpenClawRestart() itself, so every caller — including the embedded agent /restart path — gets port cleanup before the service manager restart command fires. Closes openclaw#26736 Made-with: Cursor
Contributor
Greptile SummaryThis PR fixes a crash loop issue when Key implementation details:
The implementation is defensive with proper error handling, timeout protection on all spawn calls, and tests covering the core functionality. Confidence Score: 5/5
Last reviewed commit: bc37b36 |
Contributor
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
Addresses the second trigger path described in #26736 (comment by @doomsday616).
/restartcommand runs inside an embedded agent process (openclaw agent --message), there is no SIGUSR1 listener, so it falls through totriggerOpenClawRestart(). This callslaunchctl kickstart -kdirectly — bypassing the pre-restart port cleanup added in fix(gateway): kill stale processes before restart to prevent port conflicts #27013. If the gateway was originally started via TUI/CLI, the orphaned process still holds port 18789 and the new launchd instance enters a crash loop.triggerOpenClawRestart():findGatewayPidsOnPortSync(port)— useslsof(sync viaspawnSync) to find openclaw gateway processes holding the portterminateStaleProcessesSync(pids)— SIGTERM → 300ms wait → SIGKILL for survivors → 200ms waitcleanStaleGatewayProcessesSync()— resolves gateway port from env/defaults and runs the abovetriggerOpenClawRestart(), before anylaunchctl/systemctlcommandThis ensures every caller of
triggerOpenClawRestart()gets port cleanup — not just the CLIopenclaw gateway restartpath.Test plan
findGatewayPidsOnPortSyncreturns empty array for unused portstsc --noEmit)/restartfrom embedded agent, verify clean restart without crash loopCloses #26736