fix(cli): prevent EADDRINUSE when server already running (#3346)#3388
Merged
Conversation
ag run now checks the Aegis PID file as a fallback when the health endpoint times out. If a PID file exists with a live process, the CLI assumes the server is running and skips the bootstrap/start phase. Also improved the server's EADDRINUSE error message: when a peer Aegis is detected on the port, exits with a clear message telling the user to either connect to the existing server or stop it first. Fixes: #3346
When the health endpoint times out (server under load or transient issue), isServerHealthy() now falls back to checking the Aegis PID file. If a PID file exists with a live process, the CLI assumes the server is running and skips bootstrap/start — preventing EADDRINUSE.
Contributor
There was a problem hiding this comment.
✅ Approved.
Two-part EADDRINUSE fix:
isServerHealthy()falls back to PID file check when/v1/healthtimes out — prevents CLI from thinking server is down when it's just slow.startup.tsgives clear message +ag stopsuggestion instead of raw stack trace.
Clean implementation, standard POSIX PID check via process.kill(pid, 0). CI green. All gates pass.
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
Fixes #3346 — ag run fails with EADDRINUSE when server already running.
Changes
CLI health check fallback (src/commands/run.ts): When the health endpoint times out or returns a non-OK status, falls back to checking the Aegis PID file. If a live process exists, assumes the server is running and skips bootstrap/start.
Server EADDRINUSE message (src/startup.ts): When a peer Aegis is detected on the port (already fixed by Hermes in a prior commit on this branch), exits with a clear message instead of a raw stack trace.
Verification