Skip to content

device-rotate.e2e.test.ts starts workers on the default HTTP port 4701 and fails with EADDRINUSE beside other daemon test files #1414

Closed

Description

@V3RON

src/daemon/device-rotate.e2e.test.ts:73: startWorker sets http only when a test passes httpPort. The other tests leave HTTP at the worker default (ADR 0046), 127.0.0.1:4701 (src/core/config.ts:1027). When another file in the same run also binds 4701, up to four rotate tests fail:

pnpm exec vitest run --project unit src/core/registry-state-db.test.ts src/daemon src/leasing
FAIL src/daemon/device-rotate.e2e.test.ts > device.rotate > answers a holder's rotate of its iOS-simulator lease ...
Error: listen EADDRINUSE: address already in use 127.0.0.1:4701

This failed in 1 of 8 runs of that set on main (0ebd818), and in every run when two copies of the set ran at once. Nothing on the host was listening on 4701 (lsof). Run alone, the file passes (6/6). src/daemon/test-main.ts:15 warns about this clash.

Found while triaging #1412.

Written by an agent.

Activity

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

    @V3RON
    ContributorAuthor

    Reproduction

    Confirmed. The test holds 127.0.0.1:4701 itself, so the bug shows on every run, not 1 in 8.

    src/daemon/device-rotate.e2e.test.ts › "starts a worker that asks for no HTTP port while another listener holds the standalone worker's default HTTP port 4701" (branch bug/1414-repro):

    pnpm exec vitest run --project unit src/daemon/device-rotate.e2e.test.ts
    FAIL ... > device.rotate > starts a worker that asks for no HTTP port while another listener holds ...
    AssertionError: promise rejected "Error: listen EADDRINUSE: address already…" instead of resolving
     ❯ src/daemon/device-rotate.e2e.test.ts:116:10
    Tests  1 failed | 6 passed (7)
    

    Root cause

    Defect in the test helper. src/daemon/device-rotate.e2e.test.ts:73 sets http only when the test passes httpPort. When it does not, the worker keeps the standalone default: HTTP on, at 127.0.0.1:4701 (src/core/config.ts:1025-1027, ADR 0046). So the four tests that call worker() with no port bind 4701, and any other process holding 4701 fails their start. The joined worker in the HTTP test is not hit, because its HTTP is off by default.

    Simplest fix

    When httpPort is undefined, startWorker sets http: { enabled: false }, as STANDALONE_OFF in test-main.ts:15 does.

    http:
      options.httpPort === undefined
        ? { enabled: false }
        : { enabled: true, host: "127.0.0.1", port: options.httpPort },
    pnpm exec vitest run --project unit src/daemon/device-rotate.e2e.test.ts src/daemon/input-lease.e2e.test.ts
    Test Files  2 passed (2)   Tests  11 passed (11)
    

    Alternatives rejected

    • Use startOnFreePort for every rotate test: they never call HTTP, so a port they don't need is just more setup.
    • Spread STANDALONE_OFF: it also turns agent-device off, which this bug does not need.

    Risk

    • The HTTP test (POST /v1/leases/{id}/rotate) still passes its own port, on both the worker and the gateway path.

    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 7, 2026
  5. added
    bug:ready
    fast-track
    and removed
    bug:new
    on Nov 7, 2026
  6. self-assigned this
    on Nov 7, 2026
  7. V3RON commented on Nov 7, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #1418 (#1414)
    Parked: none
    Waiting: none
    Decided: none

    Written by an agent.

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

Metadata

Metadata

Assignees

Labels

bug:readyfast-track

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions