Skip to content

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

Closed

Description

@V3RON

CI run 42239999547 (PR #1393): the test failed after 29 ms with listen EADDRINUSE: address already in use 127.0.0.1:38067, not on its timing. freeLoopbackPort in src/daemon/test-relay-support.ts picks a port, closes the server and returns the number, so another process can take it before the gateway binds it (pick-then-bind race). The PR does not touch that helper; the same file passed 3 of 3 times locally on the PR head.

Written by an agent.

Activity

  1. added
    bug:new
    flaky-test
    on Nov 6, 2026
  2. self-assigned this
    on Nov 6, 2026
  3. V3RON commented on Nov 6, 2026

    @V3RON
    ContributorAuthor

    Reproduction

    Confirmed: the pick-then-bind race is real. In this file the likely thief is the test's own counting proxy, not another process. New test on bug/1394-repro in src/daemon/relay-gateway.e2e.test.ts: "startFleet starts its gateway when the gatewayUrl hook opens a listener on the gateway's port, and the hook's listener does not get that port". The hook listens on the picked port, which forces the case where the proxy's listen(0) draws that port.

    pnpm exec vitest run --project unit src/daemon/relay-gateway.e2e.test.ts -t "gatewayUrl hook"
    AssertionError: expected 'EADDRINUSE' to be 'started'
     ❯ src/daemon/relay-gateway.e2e.test.ts:289:21
    

    Root cause

    Defect. startFleet (src/daemon/test-relay-support.ts:337-341) picks a port, then calls gatewayUrl(port) at line 338, and only after that starts the gateway on the port (line 341). The timing file's hook starts startCountingProxy, and its listen(0) (line 449) can draw the port that was just freed. The timing lane runs files one at a time, and that CI job ran only that lane. So inside that window the proxy is the only TCP bind in the repo's code.

    vitest.config.ts:34   fileParallelism: false   (timing project)
    CI job log:  × a 64 MiB download ... 29ms
                 Error: listen EADDRINUSE: address already in use 127.0.0.1:38067
    

    Simplest fix

    Move line 338 below daemons.push(gateway): the hook runs only after the gateway listens. The gateway does not read workerDials; only the worker does.

    repro: 1 passed; relay-gateway.e2e.test.ts: 33/33; relay-promises.timing.test.ts: 8/8
    

    Alternatives rejected

    • Retry the start on EADDRINUSE with a new port: the hook would run again, the proxy from the first try would still be in proxies[0], and the timing file reads proxies[0].
    • Let http.port take 0: that is a public config change (config.test.ts:1122 refuses it).

    Risk

    • A process outside this process can still take the port in the remaining window. That is the parallel-lane case, filed separately.

    Fast track

    • Defect: yes
    • Fix tried: yes
    • Nothing public added or broken: yes
    • No ADR or rule changed: yes
    • One fix: yes

    Side findings

    Written by an agent.

  4. removed their assignment
    on Nov 6, 2026
  5. added
    bug:ready
    fast-track
    and removed
    bug:new
    on Nov 6, 2026
  6. self-assigned this
    on Nov 6, 2026
  7. V3RON commented on Nov 6, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #1396 (#1394)
    Parked: none
    Waiting: none
    Decided: none

    Written by an agent.

  8. added a commit that references this issue on Nov 10, 2026
    a4e5e7d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug:readyfast-trackflaky-test

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions