Repository navigation
test(updater): take the managed bridge's port from below the ports the system hands out - #3590
Conversation
…e system hands out 'hands over to the installed release's own supervisor' timed out in CI twice, green on a rerun. Both logs show the bridge's first start failing with EADDRINUSE on the fixture's port. The fixture asked the system for a port (port 0), gave it back, and the bridge bound it 0.3 to 0.9 s later, three process starts on. On Linux the next port-0 listener in the network namespace can be handed that port meanwhile, and the integration files running beside this one start such servers in most tests. The test then polled a launcher that had already exited until its 12 s were over. The fixture now takes a random port in 10000-19999, bound once to make sure it is free: under every system's own range, and under the block scripts/check.test.ts uses. No wait, timeout or assertion changed. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
Merge passMerged head
One reviewer: owner's test-only PR: one test file. Test-only: one reviewer (Codex Terra), CLEAR with no findings. Fixes a flake that blocked CI or local merge gates on 2026-11-10; the cause was reproduced by forcing the losing order in the runner image. |
…s no other test (#3604) ## Why #3602's local merge gate failed Fast checks on two tests of `server/machine-core-choice.test.ts` that its diff does not touch: "chooses the PC's own core server: server error later" (`Expected: "Bearer aaaa…"`, `Received: null` at the relay's check of the request's token, with `GET - /api/health failed`) and, in its wake, "server error after proof" (`Executable not found in $PATH: "ssh"`). That test's relay stands on a port the system handed out (the server under test takes one with port 0 for its tunnel) and checks the token of every request it gets. The server under test never asks a tunnel for `/api/health` without the token, so the request came from another process. `scripts/plugin.test.ts` was running beside it (51.7 s in that lane). It took a port with port 0, let it go and handed it to `scripts/plugin.ts` as `PORT`. The plugin asks that port for `/api/health`, with no token, for as long as it waits for a server: seconds. Every other unit file's servers are on ports the system hands out the same way, in the same container, so one that was given the plugin's port got the plugin's question. Which process sent the request in the gate run is not in its log; the plugin tests are the only ones found that ask a port they do not hold for `/api/health` without a token. ## What `scripts/quiet-port.ts`: a free loopback port outside the ports the system hands out for port 0, so no port-0 server can be on it. The range is read from the host (`ip_local_port_range`; where it cannot be read, every port from 32768 up counts, which covers macOS and Windows), and the port is picked from a stretch of at least a thousand that holds none of them, from 20000 up when that fits. A process is never given the same port twice. `scripts/plugin.test.ts` (four places) and `scripts/plugin-phone.test.ts` hand the plugin such a port. Test-only. No assertion, wait or timeout changed, and `server/machine-core-choice.test.ts` still checks every request's token. ## Proof In the CI runner image (`herdr-ci-runner:local`): | Run | Result | |---|---| | `main`'s `machine-core-choice.test.ts` + one tokenless `GET /api/health` sent to its relay during "server error later" (scratch patch) | the gate's two failures with the gate's messages, `42 pass, 2 fail` | | `main`'s plugin tests beside 4000 listeners that keep taking ports with port 0 and letting them go | 9 tokenless `GET /api/health` arrived at those listeners, on 2 ports; two plugin tests failed themselves ("starts at the same moment", their port taken by a listener) | | this branch, the same listeners | 0 arrived; those two tests pass | ## Validation - `bun run check fast`: pass on this head (15015 unit tests pass, 0 fail). - `bun test ./scripts/quiet-port.test.ts ./scripts/plugin.test.ts ./scripts/plugin-phone.test.ts`: 56 pass on this PC. - The listener runs above were made on the first commit; the second changes only where the port is picked from (on this host and in the image, 20000 to 32767). - Skipped: `bun run check full`, the integration and browser suites (two unit test files and a test helper, no product code). No changelog fragment: nothing a user notices. - In the bare container used for the listener runs, one plugin test ("run the release the app updated to as link") fails on `main` and on this branch alike (`This PC is already in an Ovis account`); it passes under `bun run check fast` and is not about ports. ## Not in this PR - `scripts/windows-plugin.test.ts:180` takes its port the same way (it runs on Windows only, in a job of its own). - Tests that send one request to a port they just let go (`server/push.test.ts:1208`, `server/bridge.test.ts:327`, `server/ssh.test.ts:236`, `server/relay/direct.contract.test.ts:361`, `scripts/check.test.ts:200`): one request within a moment of the release, where the plugin asks for seconds. - `server/updater.test.ts` has its own picker from #3590 (10000 to 19999, fixed); `quietPort()` stays above it wherever the host's range allows. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5.2 <[email protected]>
Why
server/updater.test.ts"hands over to the installed release's own supervisor" timed out in CI twice in the last 1000 runs (run 42796212385 attempt 1 on #3544, run 42475916339 attempt 1), green on a rerun.Both logs show the same three errors: the bridge's first start fails with
EADDRINUSEon the fixture's port (Failed to start server. Is port 37195 in use?), thenThe new bridge failed its startup health check., thenManaged update timeout: nullafter the helper's 12 s. So the timeout is a symptom: the test polled a launcher that had already exited.The fixture asked the system for a port (
port: 0), gave it back, and the bridge bound it 0.3 to 0.9 s later, three process starts on (launcher, supervisor, bridge). On Linux the nextport: 0listener in the network namespace can be handed that port in the gap. The integration files run side by side, and five of the seven running beside it at that moment startport: 0servers in their tests.It is not the test's time budget (it needs 1.5 to 4 s of its 30) and not the product's hand-over: the failing bind is the first bridge start, before any update. A real install's port is 7317, outside the range.
What
managedFixturetakes its port frombridgePort(): a random port in 10000 to 19999, bound once on 127.0.0.1 to make sure it is free, then given back. That is under the ports every system hands out on its own (Linux from 32768, macOS and Windows from 49152) and under the blockscripts/check.test.tsuses, which follows the same rule (#1939, #1940). All six managed tests share the fixture. Test-only: no wait, timeout, retry or assertion changed.Proof
In the CI runner image (herdr 0.9.3, Bun 1.4.2), a container of its own, on
main03481c8:main+ a stand-in that listens on port 0 until the kernel hands it the fixture's port (a scratch patch, not in this PR)mainbeside 3000 new port-0 listeners a second, each open 2 sMeasured there: a port-0 listener gets an odd port from 32769 up first (both CI ports are of that kind); with all 28,232 ports of the range handed out, none was outside it and 32767 still bound.
Validation
bun run check fast: pass on this head (14798 unit tests pass, 0 fail).bun run check run -- env HERDR_TEST_MODE=integration bun test --timeout 15000 ./server/updater.test.tsin the runner image: the rows above.Not in this PR
The same take-a-port-and-give-it-back pattern, found by reading, none seen failing in the 74 failed Integration jobs of the last 1000 runs:
scripts/update-browser-qa.ts:46(the identical two lines; a fix there must avoid 10080, which Chromium refuses),scripts/plugin.test.ts,scripts/plugin-phone.test.ts,scripts/windows-plugin.test.ts,scripts/check.test.ts:199,server/pc-install.test.ts:94,server/ssh.test.ts:236,server/push.test.ts:1208,server/bridge.test.ts:327.scripts/check.ts's default lock ports (41737 and after) lie inside the kernel's range, so a port-0 listener can sit on one andbun run check runthen refuses as busy;server/machines.ts'sfreePort()forssh.forwardhas the same shape (impact not assessed).🤖 Generated with Claude Code