Skip to content

Two daemon unit tests start a gateway on the default port 4700 and fail when a real gateway runs on the host #1382

Closed

Description

@V3RON

Two unit tests fail with listen EADDRINUSE: address already in use 127.0.0.1:4700 on a machine where a Simlock gateway is running. They fail the same way on main with no change applied.

FAIL src/daemon/main.test.ts > startDaemon state.db > a worker's state.db holds both platforms' source-data tables, a gateway's holds neither
FAIL src/daemon/main-update.test.ts > startDaemon version check > a daemon runs the version check at start ...
Error: listen EADDRINUSE: address already in use 127.0.0.1:4700
$ lsof -nP -iTCP:4700 -sTCP:LISTEN
node 26284 ... TCP 127.0.0.1:4700 (LISTEN)

src/daemon/main.test.ts:1849 starts with role: "gateway" and no http.port, so the gateway takes the default from src/core/config.ts:1007 (role === "gateway" ? 4700 : 4701). The tests should pass a free port or port 0.

Found while triaging #1367.

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: on this host a gateway holds 127.0.0.1:4700 (lsof below), and exactly the two tests named in the issue fail. Test on bug/1382-repro: src/daemon/main-update.test.ts › "a gateway started by test-main's start helper and by this file's startChecked starts while 127.0.0.1:4700 is taken". It takes 4700 itself when the port is free, so it fails on CI too.

    $ lsof -nP -iTCP:4700 -sTCP:LISTEN
    node 26284 ... TCP 127.0.0.1:4700 (LISTEN)
    $ pnpm exec vitest run --project unit src/daemon/main-update.test.ts -t "is taken"
    AssertionError: expected [ …(2) ] to deeply equal [ 'started', 'started' ]
    +   "Error: listen EADDRINUSE: address already in use 127.0.0.1:4700",
    +   "Error: listen EADDRINUSE: address already in use 127.0.0.1:4700",
    

    Root cause

    Defect, in the test helpers. src/daemon/test-main.ts:44 (start) and src/daemon/main-update.test.ts:42 (startChecked) give a gateway no http override. The defaults at src/core/config.ts:1007 then turn HTTP on at 4700. The symptoms show at main.test.ts:1849 and main-update.test.ts:340, the only callers that start a gateway with no port. Other callers already pass freeLoopbackPort().

    Simplest fix

    In both helpers, give a gateway { http: { enabled: true, host: "127.0.0.1", port: await freeLoopbackPort() } } under the caller's overrides. Tried it:

    $ pnpm exec vitest run --project unit src/daemon/{main-stop,main-update,main-agent-device,main-host-load,driver-discovery,main}.test.ts
     Test Files  6 passed (6)
          Tests  170 passed (170)
    

    Alternatives rejected

    • Pass a port at the two call sites only: the next gateway test that uses the helpers has the same bug.
    • http: { enabled: false } for a gateway: config refuses it (config.test.ts:1636).

    Risk

    • A caller's own http override must still win: spread the default first.

    Fast track

    • Defect: yes
    • Fix tried: yes
    • 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. 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: #1383 (#1382)
    Parked: none
    Waiting: none
    Decided: none

    Written by an agent.

  8. added a commit that references this issue on Nov 10, 2026
    f427a3d
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