Conversation
…in-use bind
Previously a stale listener on 6688 (or whichever port was requested) meant
every subsequent `aexon aevatar web` failed with a bind error and the user
had to hunt down and kill the leftover process by hand. This was
particularly annoying because the most common leftover is the *previous*
aexon session — the user was already committed to running the web UI on
that port.
On an `AddressAlreadyInUse` socket error, the host now:
1. Walks the exception chain to confirm it's really a bind failure
(`SocketException.SocketErrorCode == AddressAlreadyInUse`).
2. Probes the OS for the PID(s) holding the port —
`lsof -ti :<port> -sTCP:LISTEN` on macOS/Linux,
`netstat -ano -p tcp` on Windows.
3. Kills each holder (skipping itself, just in case) and waits up to 2s
per process for a clean exit.
4. Retries `StartOnceAsync` exactly once. A second failure propagates so
the user still gets a real error message for anything we can't recover
from (stuck TIME_WAIT on a non-loopback bind, permission denied, etc.).
Smoke-tested: a Python squatter on an arbitrary port gets identified
(pid + process name logged), killed, and the web UI boots on the same
port with `/api/health` responding normally on the retry.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Follow-up to #80 — the port-auto-kill commit missed the merge window. Without this, a stale listener on 6688 (usually the previous
aexon aevatar websession) forces the user to hunt down and kill the leftover by hand.What it does
On an
AddressAlreadyInUsebind failure,AevatarWebHostnow:SocketException.SocketErrorCode == AddressAlreadyInUse) — nothing else is caught.lsof -ti :<port> -sTCP:LISTENnetstat -ano -p tcpStartOnceAsyncexactly once. A second failure propagates the real error.Test plan
dotnet build src/Aexon.Cli/Aexon.Cli.csproj— clean.aexon aevatar web --port <squatted>identifies the pid, kills it (log shows→ killing pid N (Python)), and the web UI boots normally with/api/healthresponding on the retry.Aevatar|Storage|BuiltinCommandsfilters, 132 tests) — all pass.aexon aevatar webtwice in quick succession (the second would previously fail withFailed to bind to address http://127.0.0.1:6688) and confirm the second run auto-frees and comes up.