Repository navigation
One listen socket per resolved address (#6) - #13
Merged
Merged
Conversation
A listen selection could resolve to several addresses, but the server opened a single socket, so `--host tailnet` bound the tailnet address and dropped loopback. That contradicted ADR 0003, whose rule is that loopback is always bound alongside every selected interface. `ResolvedListenAddress` now carries `bindHosts`, every address to bind, loopback first. `HttpServerLive` calls the platform server constructor once per address and fans `serve` out over all of them, so each address gets its own listening socket and nothing binds a wildcard unless a wildcard was asked for. The first bind fixes the port, which keeps `--port 0` landing every address on one ephemeral port. Local clients and URLs stay on loopback; `connectionHost` points remote clients at the first non-loopback address. The Seam 1 harness probes the runner's own LAN and Tailscale addresses rather than faking unbindable ones, and skips when the runner has none. Its TCP probe now closes politely and waits for the socket to close: the old `destroy()` left the server reaping a half-open connection, which raced scope teardown and failed the multi-bind cases about 15% of runs.
With more than one listener, naming a single origin hid where the server actually answers. Persisted runtime state gains an `addresses` field and the headless startup output gains a `Listening on:` line. Both list every bound address; `origin` and the connection string still name the one address a local CLI or a remote client should dial.
The interim recorded that a non-loopback selection bound its first non-loopback address and skipped loopback. Multi-bind retires it, so the ADR reads as its original rule again.
Carrying the first listener's port to the rest cast its address to `TcpAddress`, which lies when the bind is a Unix socket. Narrow on the tag instead and fall back to the configured port, and give the second diagnostic suppression the same reason as the first.
The Seam 1 multi-bind cases only probed raw TCP, so a fan-out that installed the request handler on the primary listener alone would still have reported both addresses accepting. The harness can now read the `/api/auth/session` descriptor over a specific bound address, and the multi-bind cases read it over each one, which is what separates a real per-address bind from a single listener. Adds the case the acceptance criteria asked for, an explicit address on no interface alongside a real one, so the surviving address is bound rather than only loopback. Adds a shutdown case proving every listener is released, by taking the addresses for this process once the scope closes: a connect to a closed port on a LAN address is dropped rather than refused, so probing it would only hang. Runtime state now has a case covering a selection that bound more than one address.
9 tasks
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.
Ticket: #6 (parent spec #1, ADR 0003).
One listen socket per resolved address: the HTTP server layer is made once per address and fanned out; nothing binds
0.0.0.0unless the legacy wildcard is requested. Loopback is bound alongside every selected interface again, so the single-socket interim paragraph is removed from ADR 0003. Runtime state and startup output list every bound address.Verification: Node is the CI runtime, proven by the Seam 1 suite (9 cases): every bound address serves
/api/auth/sessionover HTTP (not just an open socket), a real address survives a skipped explicit one (lan,203.0.113.7), and shutdown releases every listener (rebinding the addresses after scope close). Bun verified manually: twoBun.serveinstances on one ephemeral port, both returning 200. The{loopback, tailnet}case runs only on a tailnet-connected machine and skips with a message elsewhere, as the ticket requires.Behaviour note: the server's own origin URL now uses the first bound address, which is loopback for any interface selection. The four consumers are local CLIs (
connect,project,pair,auth) that previously depended on the tailnet interface being up, so this is an improvement.Review items declined, with reasons:
ResolvedListenAddress.kindis pre-existing dead weight unrelated to this ticket; persistedaddressesis spec-mandated even before a UI reads it;--port 0collision retry is unwarranted for a failure not observed in 500 trials;skipIffor the tailnet case is what the ticket asks for.Known gap: the desktop still expresses a single address; #7 changes that.