Skip to content

test(updater): take the managed bridge's port from below the ports the system hands out - #3590

Merged
devswha merged 1 commit into
mainfrom
test/updater-handover-timeout
Nov 10, 2026
Merged

devswha merged 1 commit into
mainfrom
test/updater-handover-timeout

Conversation

@devswha

@devswha devswha commented Nov 10, 2026

Copy link
Copy Markdown
Owner

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 EADDRINUSE on the fixture's port (Failed to start server. Is port 37195 in use?), then The new bridge failed its startup health check., then Managed update timeout: null after 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 next port: 0 listener 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 start port: 0 servers 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

managedFixture takes its port from bridgePort(): 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 block scripts/check.test.ts uses, 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 main 03481c8:

Run Result
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) fails 3 of 3 with the CI errors, at 12207, 12315 and 12341 ms (CI: 12345 and 12157 ms)
this change + the same stand-in passes 3 of 3: the stand-in uses up the kernel's 7,058 first-choice ports without being handed the fixture's
main beside 3000 new port-0 listeners a second, each open 2 s 4 and 5 of the six managed tests fail per run, same errors
this change beside the same churn, the file ×3 56 pass, 0 fail each
this change: the test ×20, the file ×5 20 pass; 56 pass, 0 fail each

Measured 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.ts in the runner image: the rows above.
  • Skipped: the rest of the integration suite, browser lanes, macOS (one test file's fixture changed).

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.
  • Not test code, reported only: 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 and bun run check run then refuses as busy; server/machines.ts's freePort() for ssh.forward has the same shape (impact not assessed).
  • The managed tests still wait their full 12 s when the launcher has already exited.

🤖 Generated with Claude Code

…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]>
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Tests
    • Updated test setup to choose an available local port from a defined range, retrying when a port cannot be bound. This reduces collisions during test runs and helps make automated verification more consistent. The change is limited to testing and does not affect application behavior or how the service operates in production.

The updater tests add bridgePort() to find an available loopback port between 10,000 and 19,999. managedFixture now uses this helper instead of requesting and releasing an OS-assigned ephemeral port.

Changes: Managed fixture port selection

Layer / File(s) Summary
Select and use a bridge port
server/updater.test.ts
bridgePort() tries up to 50 randomly selected ports and throws if none can be bound. managedFixture uses the selected port.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Other

Suggested reviewers: jamesyang124

Merge Risk: Minimal · up to f7f3b

The test-only change is ready to merge after normal checks; the existing port-allocation race remains possible.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title clearly identifies the updater test change and the reason for choosing a port below the system-assigned range. It is specific and relevant, though somewhat long.
Description check Passed The description explains the problem, the resulting fixture behavior, and the validation performed and skipped. It uses “What” instead of the template’s “Change” heading, but includes the required cha…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the problem, the resulting fixture behavior, and the validation performed and skipped. It uses “What” instead of the template’s “Change” heading, but includes the required change information.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 1 files.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between c94f525 and f7f3b94.

Files selected for processing: 1

  • server/updater.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

@devswha
devswha merged commit d7c4713 into main Nov 10, 2026
21 checks passed
@devswha
devswha deleted the test/updater-handover-timeout branch November 10, 2026 17:27
@devswha

devswha commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head f7f3b94a5e53 as d7c47139966b on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
codex CLEAR

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.

devswha added a commit that referenced this pull request Nov 10, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant