e2e viewer: bind any free port instead of crashing on a busy 8901 - #998
Merged
Conversation
The viewer's static server pinned port 8901 with no error handler, so it hard-crashed on EADDRINUSE — exactly the collision the per-checkout port machinery exists to prevent. Two worktrees, or a leaked previous viewer, would wedge each other. The server now walks forward from 8901 to the next free port and prints the actual bound URL. An explicit PORT still pins strictly and fails loudly if busy (the strictPort rule). The built SPA was already port- and mount-agnostic (relative assets + hash routing), so whatever port the server lands on just works in the browser.
Contributor
Cloudflare previewTorn down — the PR is closed. |
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.
What
The e2e runs viewer (
cd e2e && bun run serve) pinned port 8901 with no error handler, so it hard-crashed onEADDRINUSE. That's exactly the collision the per-checkout port machinery (e2e/src/ports.ts) exists to prevent: two worktrees — or a leaked previous viewer — would wedge each other, and on a host where 8901 is otherwise held (e.g. a tailscale-bound listener) it couldn't start at all.The viewer SPA was already port- and mount-agnostic (
base: "./", relative fetches, trace-viewer link built fromwindow.location.href). The only thing tied to a port was the static server that hosts it.Change
e2e/scripts/serve.tsnow:e2e viewer → http://localhost:<port>/).PORT=…is set explicitly — fails loudly with exit 1 if busy, matching the--strictPortrule documented inports.ts.Plus a
RUNNING.mdnote so the behavior is discoverable.Verified locally
On this host 8901 was already held on the tailscale interface, which made for a real collision test:
port 8901 in use, trying 8902…→ bound 8902;GET /→ 200 (dir→index.html),GET /manifest.json→ 200, correct body, gzip negotiation intact, range requests untouched.PORT=8901→ exit 1,e2e viewer: PORT=8901 is in use — free it or pick another port.oxfmt --check✓,oxlint --deny-warnings✓,tsc --noEmit✓.No product behavior changes; this is dev-tooling for the test viewer, so there's no e2e scenario to attach.