Skip to content

Bind the smoke server to an ephemeral port - #35

Merged
calvintvu merged 1 commit into
mainfrom
smoke-ephemeral-port
Aug 5, 2026
Merged

Bind the smoke server to an ephemeral port#35
calvintvu merged 1 commit into
mainfrom
smoke-ephemeral-port

Conversation

@calvintvu

@calvintvu calvintvu commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Context

smoke.sh tried 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 already
be in use.

Changes

  • main.go accepts --port 0, which asks the kernel for a free port. It previously rejected 0 and accepted 1 to 65535.
  • smoke.sh starts the server once on --port 0 and reads the bound address out of the listening on http://127.0.0.1:PORT line 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 0 is 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 --port help.

Test

  • make -C collector check — passed

  • make -C collector test — passed

  • make -C collector release && make smoke — passed on an ephemeral port
    (server ready on http://127.0.0.1:63008), all seven assertions

  • make -C collector build && make smoke-dev — passed, bare mode still gets
    503 on / and 200 on /api/sessions

  • Port validation at the new boundary:

    flag result
    --port -1 --port must be between 0 and 65535, got -1
    --port 0 accepted
    --port 65536 --port must be between 0 and 65535, got 65536
  • The case the loop existed for. Occupied 18787 with another listener and ran make smoke: it bound 63118 and exited 0. On main this is the run that would have consumed the first fallback.

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>
@calvintvu calvintvu added enhancement New feature or request devtools labels Aug 5, 2026
@calvintvu
calvintvu merged commit 425a8b7 into main Aug 5, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devtools enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants