Bind the smoke server to an ephemeral port - #35
Merged
Conversation
smoke.sh tried ports 18787, 18788, and 18789 in turn, with the whole startup and readiness sequence wrapped in that loop. The loop existed because a hardcoded port can already be taken. --port 0 removes the problem instead of retrying it: the kernel returns a free port, and the server already logs the address it bound, which the script already reads. Start once, read the port from the log, poll for readiness. A server that now fails to start is a real error rather than a busy port, so the script says so instead of trying the next candidate. main.go accepted 1 to 65535 and rejected 0. It now accepts 0 as "pick any free port", which is also useful on the command line and is documented in --port help. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
luhe19001
approved these changes
Aug 5, 2026
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.
Context
smoke.shtried ports 18787, 18788, and 18789 in turn, with the whole startup and readiness sequence wrapped in that loop, plus a separate error path for "all three were taken". The loop existed because a hardcoded port can alreadybe in use.
Changes
main.goaccepts--port 0, which asks the kernel for a free port. It previously rejected 0 and accepted 1 to 65535.smoke.shstarts the server once on--port 0and reads the bound address out of thelistening on http://127.0.0.1:PORTline the server already logs.This removes the collision instead of retrying it. A server that fails to start is now always a real error, so the script reports it rather than trying the next candidate.
--port 0is not a test-only affordance — "give me any free port" is a reasonable thing to ask of a local tool, and the startup log already prints where it landed. It is documented in--porthelp.Test
make -C collector check— passedmake -C collector test— passedmake -C collector release && make smoke— passed on an ephemeral port(
server ready on http://127.0.0.1:63008), all seven assertionsmake -C collector build && make smoke-dev— passed, bare mode still gets503 on
/and 200 on/api/sessionsPort validation at the new boundary:
--port -1--port must be between 0 and 65535, got -1--port 0--port 65536--port must be between 0 and 65535, got 65536The case the loop existed for. Occupied 18787 with another listener and ran
make smoke: it bound 63118 and exited 0. Onmainthis is the run that would have consumed the first fallback.