Skip to content

e2e flows start a daemon on a released free port without withHttpDaemon's retry #1397

Closed as not planned

Description

@V3RON

withHttpDaemon (e2e/helpers/http-daemon.ts:13, #560) retries when the port freeLoopbackPort released is taken before the daemon binds it. Some e2e flows still pass that port straight to a daemon, so the e2e lane (4 workers) can fail them with EADDRINUSE:

e2e/lease-limit-per-requester.test.ts:91
e2e/usage-stats.test.ts:125
e2e/physical-leasing.test.ts:699
e2e/daemon-folders.test.ts:28
e2e/daemon-lifecycle.test.ts:79

Not checked: the slow-lane files and e2e/console/fixtures.ts. Found while triaging #1395.

Written by an agent.

Activity

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

    @V3RON
    ContributorAuthor

    Reproduction

    Confirmed, and wider: 27 flows in 8 files. Test on bug/1397-repro: e2e/picked-ports.test.ts, "the flows that start a daemon on a port they picked pass when another listener takes the first port each one releases". A child vitest run takes and holds the first port each test releases. The control, a GET /v1/stats flow on withHttpDaemon, passes. Without the taker, all 102 tests of those files pass.

    pnpm test:e2e e2e/picked-ports.test.ts
    -   "cancelled when its requester cancels": "passed",
    +   "cancelled when its requester cancels": "failed",
        ... 27 flows "failed"; the withHttpDaemon control "passed"
     ❯ e2e/picked-ports.test.ts:147:24
    

    Root cause

    Defect. freeLoopbackPort (e2e/helpers/port.ts:21) and three local reservePort copies (http-api.test.ts:15, daemon-log.test.ts:47, device-exec.test.ts:23) release the port before returning it. The flows hand it to a daemon that binds later with no retry, so a port taken in between fails the start with EADDRINUSE. Sites the issue missed: http-api.test.ts (60, 216, 315, 348, 420, 469, 512), daemon-log.test.ts:95, device-exec.test.ts:83. Only withHttpDaemon (e2e/helpers/http-daemon.ts:13) retries.

    Simplest fix

    1. Switch to withHttpDaemon at lease-limit-per-requester:91, usage-stats:125, physical-leasing:699, the 7 http-api sites, daemon-log:95 and device-exec:83. Delete the reservePort copies.
    2. daemon-folders and daemon-lifecycle:79 start the gateway inside the test (config set, then a start, status or MCP call, or a spawned main.js): move withHttpDaemon's loop into onFreePort(start: (port) => Promise<"started" | "port-taken">) and wrap that step.

    Step 1 tried on 3 files: their 7 flows pass, the files stay green:

    pnpm test:e2e e2e/picked-ports.test.ts e2e/device-exec.test.ts e2e/daemon-log.test.ts e2e/lease-limit-per-requester.test.ts
    Tests  1 failed | 15 passed (16)   # picked-ports: those 7 "passed", the other 20 still "failed"
    

    Alternatives rejected

    Risk

    • About 9 files, over the gate's 8: two PRs, step 1 then step 2.
    • The reproduction reruns 28 flows (about 30 s green, 2.7 min red): keep it or drop it after the fix.
    • Not checked: the slow lane, e2e/console/fixtures.ts (221, 596, 643), e2e/helpers/env.test.ts:114, the registry port in e2e/update/update.e2e.test.ts:22.

    Fast track

    • Defect: yes
    • Fix tried: no — tried on 3 of 8 files
    • Nothing public added or broken: yes
    • No ADR or rule changed: yes
    • One fix: yes

    Written by an agent.

  4. removed their assignment
    on Nov 6, 2026
  5. V3RON commented on Nov 6, 2026

    @V3RON
    ContributorAuthor

    Closing as a duplicate of #1395 at the maintainer's request. Its e2e call sites are now part of #1395's scope (comment "Scope added: the e2e flows (from #1397)"). The repro test stays on bug/1397-repro.

    Written by an agent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug:new

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions