You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Test helpers pick a loopback port, release it, and bind it later: any process in a parallel lane can take it first #1395
14 files under src/ define a freeLoopbackPort that listens on port 0, closes the server and returns the number (e.g. src/daemon/test-relay-support.ts:30, src/agent-device/test-support.ts:139, src/daemon/input-lease.e2e.test.ts:17). The caller binds the number later. The unit lane runs files in parallel processes (vitest.config.ts), so another file's listen(0) can draw the same port in that window and the bind fails with EADDRINUSE. No failure seen yet outside the timing lane; #1394's cause is the in-process case. Found while triaging #1394.
Confirmed. Test on bug/1395-repro: src/agent-device/rig-ports.e2e.test.ts, "start their daemon on another port when another listener takes the port they picked before the daemon binds it". It covers the two shared rigs (startFleet, the agent-device setUp). The stand-in for another process takes the port the moment the rig's listener closes.
Defect. freeLoopbackPort (src/daemon/test-relay-support.ts:30-37, and the 13 copies the issue names) closes its listener before it returns the port. The daemon binds that port only after its socket claim (src/daemon/worker-composition.ts:612, a gateway at main.ts:613). If the port is taken in that window, the start rejects with EADDRINUSE (worker-composition.ts:692, main.ts:616), and no rig retries. The e2e lane already retries this case (withHttpDaemon, e2e/helpers/http-daemon.ts:13, #560). The in-process rigs never got that retry.
Simplest fix
Add one src/test-support/loopback-port.ts with freeLoopbackPort and startOnFreePort(start). startOnFreePort picks a new port on EADDRINUSE, up to 5 tries. Wrap each of the 14 rigs' daemon start in it and delete the copies. Tried on the two shared rigs only:
The same released-port bug in e2e/, from #1397 (27 flows in 8 files). Triage report and repro test: #1397's comment, test e2e/picked-ports.test.ts on branch bug/1397-repro.
e2e/helpers/port.ts:21freeLoopbackPort and three local reservePort copies (e2e/http-api.test.ts:15, e2e/daemon-log.test.ts:47, e2e/device-exec.test.ts:23) release the port before a daemon in another process binds it. Only withHttpDaemon (e2e/helpers/http-daemon.ts:13) retries.
Switch to withHttpDaemon: lease-limit-per-requester:91, usage-stats:125, physical-leasing:699, http-api (60, 216, 315, 348, 420, 469, 512), daemon-log:95, device-exec:83. Delete the reservePort copies.
daemon-folders and daemon-lifecycle:79 start the gateway inside the test: wrap that step in the same retry as startOnFreePort. One helper for src/ and e2e/, not two.
The src/ callers that still pass a released port to startDaemon through the re-export in src/daemon/test-relay-support.ts:21 also start through startOnFreePort: src/daemon/test-main.ts (36, 185), main-stop.test.ts (95, 485, 520, 605, 607, 684, 720), main.test.ts (1445, 1470, 1652, 1680, 1764), main-update.test.ts (52, 401), main-host-load.test.ts:308, main-agent-device.test.ts:396.
Done when (added)
e2e/picked-ports.test.ts passes: every flow "passed" with the port taker running.
Activity
test: reproduce #1395 — the shared daemon test rigs fail with EADDRIN…
V3RON commentedon Nov 6, 2026
Reproduction
Confirmed. Test on
bug/1395-repro:src/agent-device/rig-ports.e2e.test.ts, "start their daemon on another port when another listener takes the port they picked before the daemon binds it". It covers the two shared rigs (startFleet, the agent-devicesetUp). The stand-in for another process takes the port the moment the rig's listener closes.Root cause
Defect.
freeLoopbackPort(src/daemon/test-relay-support.ts:30-37, and the 13 copies the issue names) closes its listener before it returns the port. The daemon binds that port only after its socket claim (src/daemon/worker-composition.ts:612, a gateway atmain.ts:613). If the port is taken in that window, the start rejects with EADDRINUSE (worker-composition.ts:692,main.ts:616), and no rig retries. The e2e lane already retries this case (withHttpDaemon,e2e/helpers/http-daemon.ts:13, #560). The in-process rigs never got that retry.Simplest fix
Add one
src/test-support/loopback-port.tswithfreeLoopbackPortandstartOnFreePort(start).startOnFreePortpicks a new port on EADDRINUSE, up to 5 tries. Wrap each of the 14 rigs' daemon start in it and delete the copies. Tried on the two shared rigs only:Alternatives rejected
http.portrefuses 0, and the local profile and the advertised URLs read the configured port.Risk
slowStartandrestartpaths still bind a known port, with no retry.gatewayUrlhook runs on every try. It is safe once Flaky: relay-promises.timing.test.ts "a 64 MiB download through the gateway arrives byte for byte and finishes within 2.8 s" fails with EADDRINUSE #1394's fix runs it after the bind.Fast track
Side findings
Written by an agent.
docs(test-support): the manual names startOnFreePort (#1395)
V3RON commentedon Nov 6, 2026
Added scope (maintainer, 2026-11-06)
The same released-port bug in
e2e/, from #1397 (27 flows in 8 files). Triage report and repro test: #1397's comment, teste2e/picked-ports.test.tson branchbug/1397-repro.e2e/helpers/port.ts:21freeLoopbackPortand three localreservePortcopies (e2e/http-api.test.ts:15,e2e/daemon-log.test.ts:47,e2e/device-exec.test.ts:23) release the port before a daemon in another process binds it. OnlywithHttpDaemon(e2e/helpers/http-daemon.ts:13) retries.withHttpDaemon: lease-limit-per-requester:91, usage-stats:125, physical-leasing:699, http-api (60, 216, 315, 348, 420, 469, 512), daemon-log:95, device-exec:83. Delete thereservePortcopies.startOnFreePort. One helper forsrc/ande2e/, not two.e2e/console/fixtures.ts(221, 596, 643),e2e/helpers/env.test.ts:114,e2e/update/update.e2e.test.ts:22.src/callers that still pass a released port tostartDaemonthrough the re-export insrc/daemon/test-relay-support.ts:21also start throughstartOnFreePort:src/daemon/test-main.ts(36, 185),main-stop.test.ts(95, 485, 520, 605, 607, 684, 720),main.test.ts(1445, 1470, 1652, 1680, 1764),main-update.test.ts(52, 401),main-host-load.test.ts:308,main-agent-device.test.ts:396.Done when (added)
e2e/picked-ports.test.tspasses: every flow "passed" with the port taker running.Written by an agent.
chore(merge): bring origin/main into bug/1395 (#1395)
test: the e2e flows that start a daemon on a picked port pass when an…
fix(e2e): every e2e flow that picks a daemon port starts again on ano…
fix(daemon): the daemon test starts on a picked port take another por…
docs(test-support): the manual names the e2e re-export and withHttpDa…
docs(test-support): the startOnFreePort manual line is wrapped and re…
docs(test-support): the manual drops the startOnFreePort line that re…
refactor(e2e): the console fixture's config file is built apart from …
fix(test-support): daemon tests that start on a picked port retry a l…
chore(daemon): test-relay-support no longer re-exports freeLoopbackPo…
fix(test-support): a daemon test that retries a lost port starts the …
V3RON commentedon Nov 6, 2026
Delivery run
Merged: #1405 (#1395)
Asleep: 39 min
Written by an agent.
fix(test-support): daemon test rigs start on another port when their …