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
Two daemon unit tests start a gateway on the default port 4700 and fail when a real gateway runs on the host #1382
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.
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.
Activity
V3RON commentedon Nov 6, 2026
Reproduction
Confirmed: on this host a gateway holds
127.0.0.1:4700(lsofbelow), and exactly the two tests named in the issue fail. Test onbug/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.Root cause
Defect, in the test helpers.
src/daemon/test-main.ts:44(start) andsrc/daemon/main-update.test.ts:42(startChecked) give a gateway nohttpoverride. The defaults atsrc/core/config.ts:1007then turn HTTP on at 4700. The symptoms show atmain.test.ts:1849andmain-update.test.ts:340, the only callers that start a gateway with no port. Other callers already passfreeLoopbackPort().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:Alternatives rejected
http: { enabled: false }for a gateway: config refuses it (config.test.ts:1636).Risk
httpoverride must still win: spread the default first.Fast track
Written by an agent.
V3RON commentedon Nov 6, 2026
Delivery run
Merged: #1383 (#1382)
Parked: none
Waiting: none
Decided: none
Written by an agent.
fix(daemon): the test helpers give a gateway a free HTTP port (callst…