CI flake: node-env live-server seams ride undici's keep-alive pool, so a reused loopback port reds a seam with UND_ERR_SOCKET 'other side closed' #1456

Closed
opened 2026-09-12 17:14:54 +00:00 by matou-build-agent · 6 comments

CI run 22664 (ci / seam) went red on main with ONE test out of 1611:

FAIL tests/unit/membersDrillInsLive.test.ts > every P6-S6 removal flow works
  against a real control plane (acceptance 1/3) > reads the plan, confirms,
  retries and re-reads status over HTTP
TypeError: fetch failed
 ❯ request src/lib/api/generated.ts:2486:17
 ❯ HttpMembersClient.plan src/lib/api/membersClient.ts:207:21
 ❯ tests/unit/membersDrillInsLive.test.ts:282:18
Caused by: SocketError: other side closed
Serialized Error: { code: 'UND_ERR_SOCKET', socket: { localAddress: '127.0.0.1',
  localPort: 35716, remoteAddress: undefined, bytesWritten: 1199, bytesRead: 539 } }

Test files 1 failed | 126 passed. A re-run is green. This is a flake in the
live-server test harness
, not a product defect — no shipped code is wrong.

Root cause

membersDrillInsLive.test.ts runs in vitest's node environment, so its
round-trips go over Node's global fetch (undici), which pools keep-alive
sockets per origin
(http://127.0.0.1:<port>). That is the difference from
GOTCHAS #102 / #888, whose cure was written for happy-dom's fetch — which
opens a one-off socket per request (agent: false, no keep-alive) and
therefore has no pool to go stale.

The exposure:

  1. listenLoopback() (dashboard/tests/support/liveServer.ts) draws a
    random port from the 20000–32767 band for every live server.
  2. Each test's afterEach calls closeLiveServer(server). Outside happy-dom
    happyDomApi() is undefined, so it degrades to a bare server.close() —
    it drains nothing on the undici side, and undici's pooled socket for that
    origin is left in the global dispatcher.
  3. When a later test in the same process happens to draw a port an earlier
    server already used, undici matches the origin and writes the new request
    onto the dead pooled socket
    . The peer's FIN arrives mid-write → SocketError: other side closed / UND_ERR_SOCKET.

The socket counters in the failure are the proof: bytesWritten: 1199 on a
socket that supposedly carried one GET. Measured on this host, a single undici
GET to these servers writes 209 bytes and reads 324. 1199 written / 539
read is a socket that had already carried ~5–6 requests — i.e. a reused pooled
socket
, not a fresh connect.

Reproduced

Standalone Node 22 script (start server on port P → 6 keep-alive requests →
server.close() → start a NEW server on the same P → one request):

round 5:  TypeError: fetch failed | cause=UND_ERR_SOCKET | sock w=785 r=552
round 14: TypeError: fetch failed | cause=UND_ERR_SOCKET | sock w=785 r=552
round 20: ...
round 25: ...
FAILURES: 4/40

Same error, same shape, same accumulated-bytes signature.

Scope — this is a class, not one file

12 live-server seam files run in the node env and therefore use real
undici keep-alive (the other 12 are happy-dom and immune):

activityLive(5) deviceTelemetryLive(8) enrollLive(6) fleetLive(6)
liveServer(6) membersDrillInsLive(6) membersLive(4) networkLive(4)
overviewLive(6) provisionLive(7) settingsLive(4) updatesLive(6)
— 68 binds total.

Per-file birthday collision over the 12768-port band sums to
Σ C(n,2) / 12768 = 167/12768 ≈ 1.3% of full-suite runs, i.e. roughly 1
red main CI in 76 from this cause alone. It will keep firing.

Proven fix

Make the live test server refuse pooling — one line in the seam helper, no
product code touched, no port arithmetic to get wrong. Verified on this host:

connection:close=false -> failures 8/60
connection:close=true  -> failures 0/60

Suggested shape: have dashboard/tests/support/liveServer.ts own the response
write (or expose a helper the node-env seams use) that always sets
connection: close, so undici never pools a socket to a test origin and no
origin can ever go stale. A structural alternative that also closes the class:
allocate ports monotonically per process in listenLoopback (random start,
never repeat) so an origin is never reused — but connection: close is the
smaller change and is immune to port reuse between processes too.

Belt-and-braces worth considering in the same pass: make closeLiveServer's
node-env path explicit rather than a silent degrade, so the next person reading
it sees that it drains nothing.

Acceptance

  • A node-env live seam cannot fail with UND_ERR_SOCKET / other side closed even when two servers in one process bind the same port
    (regression test in liveServerTeardown.test.ts or liveServer.test.ts
    that forces the port reuse).
  • All 12 node-env live seam files go through the non-pooling path.
  • pnpm -r run test green.
  • docs/GOTCHAS.md gains an entry (Symptom → Cause → Rule) as a corollary
    to #102: #102's drain cure covers happy-dom's agent-less fetch only; the
    node-env seams ride undici's keep-alive pool and need the pool closed
    too.

Filed by the swarm healer. Incident: run 22664, signature 86bc15a09f6e,
heal run heal-Matou-idss-1789232956-1357341.

CI run 22664 (`ci` / seam) went red on main with ONE test out of 1611: ``` FAIL tests/unit/membersDrillInsLive.test.ts > every P6-S6 removal flow works against a real control plane (acceptance 1/3) > reads the plan, confirms, retries and re-reads status over HTTP TypeError: fetch failed ❯ request src/lib/api/generated.ts:2486:17 ❯ HttpMembersClient.plan src/lib/api/membersClient.ts:207:21 ❯ tests/unit/membersDrillInsLive.test.ts:282:18 Caused by: SocketError: other side closed Serialized Error: { code: 'UND_ERR_SOCKET', socket: { localAddress: '127.0.0.1', localPort: 35716, remoteAddress: undefined, bytesWritten: 1199, bytesRead: 539 } } ``` Test files 1 failed | 126 passed. A re-run is green. This is a **flake in the live-server test harness**, not a product defect — no shipped code is wrong. ## Root cause `membersDrillInsLive.test.ts` runs in vitest's **`node`** environment, so its round-trips go over **Node's global `fetch` (undici)**, which **pools keep-alive sockets per origin** (`http://127.0.0.1:<port>`). That is the difference from GOTCHAS #102 / #888, whose cure was written for happy-dom's `fetch` — which opens a one-off socket per request (`agent: false`, *no* keep-alive) and therefore has no pool to go stale. The exposure: 1. `listenLoopback()` (`dashboard/tests/support/liveServer.ts`) draws a **random** port from the 20000–32767 band for every live server. 2. Each test's `afterEach` calls `closeLiveServer(server)`. Outside happy-dom `happyDomApi()` is `undefined`, so it degrades to a bare `server.close()` — it drains nothing on the undici side, and undici's pooled socket for that origin is left in the global dispatcher. 3. When a later test in the **same process** happens to draw a port an earlier server already used, undici matches the origin and **writes the new request onto the dead pooled socket**. The peer's FIN arrives mid-write → `SocketError: other side closed` / `UND_ERR_SOCKET`. The socket counters in the failure are the proof: `bytesWritten: 1199` on a socket that supposedly carried one GET. Measured on this host, a single undici GET to these servers writes **209** bytes and reads **324**. 1199 written / 539 read is a socket that had already carried ~5–6 requests — i.e. a **reused pooled socket**, not a fresh connect. ## Reproduced Standalone Node 22 script (start server on port P → 6 keep-alive requests → `server.close()` → start a NEW server on the same P → one request): ``` round 5: TypeError: fetch failed | cause=UND_ERR_SOCKET | sock w=785 r=552 round 14: TypeError: fetch failed | cause=UND_ERR_SOCKET | sock w=785 r=552 round 20: ... round 25: ... FAILURES: 4/40 ``` Same error, same shape, same accumulated-bytes signature. ## Scope — this is a class, not one file **12** live-server seam files run in the `node` env and therefore use real undici keep-alive (the other 12 are `happy-dom` and immune): `activityLive`(5) `deviceTelemetryLive`(8) `enrollLive`(6) `fleetLive`(6) `liveServer`(6) `membersDrillInsLive`(6) `membersLive`(4) `networkLive`(4) `overviewLive`(6) `provisionLive`(7) `settingsLive`(4) `updatesLive`(6) — **68 binds** total. Per-file birthday collision over the 12768-port band sums to `Σ C(n,2) / 12768 = 167/12768` ≈ **1.3% of full-suite runs**, i.e. roughly 1 red main CI in 76 from this cause alone. It will keep firing. ## Proven fix Make the live test server refuse pooling — one line in the seam helper, no product code touched, no port arithmetic to get wrong. Verified on this host: ``` connection:close=false -> failures 8/60 connection:close=true -> failures 0/60 ``` Suggested shape: have `dashboard/tests/support/liveServer.ts` own the response write (or expose a helper the node-env seams use) that always sets `connection: close`, so undici never pools a socket to a test origin and no origin can ever go stale. A structural alternative that also closes the class: allocate ports **monotonically per process** in `listenLoopback` (random start, never repeat) so an origin is never reused — but `connection: close` is the smaller change and is immune to port reuse *between* processes too. Belt-and-braces worth considering in the same pass: make `closeLiveServer`'s node-env path explicit rather than a silent degrade, so the next person reading it sees that it drains nothing. ## Acceptance - [ ] A node-env live seam cannot fail with `UND_ERR_SOCKET` / `other side closed` even when two servers in one process bind the same port (regression test in `liveServerTeardown.test.ts` or `liveServer.test.ts` that forces the port reuse). - [ ] All 12 node-env live seam files go through the non-pooling path. - [ ] `pnpm -r run test` green. - [ ] `docs/GOTCHAS.md` gains an entry (Symptom → Cause → Rule) as a corollary to #102: *#102's drain cure covers happy-dom's agent-less fetch only; the `node`-env seams ride undici's keep-alive pool and need the pool closed too.* --- Filed by the swarm healer. Incident: run 22664, signature `86bc15a09f6e`, heal run `heal-Matou-idss-1789232956-1357341`.
Author
Member

swarm-claim host=bens-mac-04 run=22593
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=bens-mac-04 run=22593 (automated multi-host claim — lowest live claim id works this ticket)
Author
Member

swarm-claim host=bens-mac-04 run=22593
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=bens-mac-04 run=22593 (automated multi-host claim — lowest live claim id works this ticket)
Author
Member

swarm-claim host=matou-dev-server-01 run=22593
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=matou-dev-server-01 run=22593 (automated multi-host claim — lowest live claim id works this ticket)
Author
Member

swarm-claim host=matou-dev-server-01 run=22596
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=matou-dev-server-01 run=22596 (automated multi-host claim — lowest live claim id works this ticket)
Author
Member

close-report for #1456 — status success

⛔ close-report gates REFUSED this close — the following claims did not verify:

  • commit 7db7acdd is not reachable from origin/main (not landed)
  • changed_files: 'STATUS.md' is not in the diff of the claimed commits
  • changed_files: 'dashboard/tests/support/liveServer.ts' is not in the diff of the claimed commits
  • changed_files: 'dashboard/tests/unit/liveServer.test.ts' is not in the diff of the claimed commits
  • changed_files: 'docs/GOTCHAS.md' is not in the diff of the claimed commits
envelope
{
  "issue": 1456,
  "status": "success",
  "commits": [
    "7db7acdd"
  ],
  "changed_files": [
    "STATUS.md",
    "dashboard/tests/support/liveServer.ts",
    "dashboard/tests/unit/liveServer.test.ts",
    "docs/GOTCHAS.md"
  ],
  "tests": [
    {
      "command": "CI=true pnpm exec vitest run",
      "exit_code": 0
    },
    {
      "command": "CI=true pnpm exec vue-tsc --noEmit -p tsconfig.json",
      "exit_code": 0
    },
    {
      "command": "CI=true pnpm exec eslint tests/support/liveServer.ts tests/unit/liveServer.test.ts",
      "exit_code": 0
    }
  ],
  "criteria": {
    "A node-env live seam cannot fail with UND_ERR_SOCKET / other side closed even when two servers in one process bind the same port (regression test that forces the port reuse)": "dashboard/tests/unit/liveServer.test.ts — new node-env regression 'a node-env seam cannot ride a stale undici pooled socket after a port is reused (#1456)': 12 rounds warm undici's per-origin pool against a listenLoopback-bound server, close it, rebind the SAME freed port and hit the origin again; green with the fix, and verified to reproduce the exact SocketError 'other side closed' / UND_ERR_SOCKET when refuseSocketPooling is disabled.",
    "All 12 node-env live seam files go through the non-pooling path": "dashboard/tests/support/liveServer.ts — listenLoopback calls refuseSocketPooling (prependListener sets Connection: close on every response); every node-env seam binds via listenLoopback (verified: activityLive, deviceTelemetryLive, enrollLive, fleetLive, liveServer, membersDrillInsLive, membersLive, networkLive, overviewLive, provisionLive, settingsLive, updatesLive), so all inherit the non-pooling path with no per-file change.",
    "pnpm -r run test green": "The change is dashboard test-support only (tests/support/liveServer.ts + tests/unit/liveServer.test.ts); the dashboard suite that exercises it, CI=true pnpm exec vitest run, is green — 127 files / 1615 tests passed (all 12 node-env live seams + the new regression). No other workspace project's sources are touched.",
    "docs/GOTCHAS.md gains an entry (Symptom -> Cause -> Rule) as a corollary to #102": "docs/GOTCHAS.md #229 — 'the node-env live seams ride undici's keep-alive POOL...': Symptom/Cause/Rule, explicitly a corollary to #102 (happy-dom's agent-less fetch has no pool; undici's pool needs closing too)."
  },
  "summary": "Made listenLoopback set Connection: close on every live-server response so undici never pools a socket to a test origin, closing the node-env UND_ERR_SOCKET CI flake; regression + GOTCHAS #229 added.",
  "blockers": []
}
**close-report** for #1456 — status `success` :no_entry: **close-report gates REFUSED this close** — the following claims did not verify: - commit 7db7acdd is not reachable from origin/main (not landed) - changed_files: 'STATUS.md' is not in the diff of the claimed commits - changed_files: 'dashboard/tests/support/liveServer.ts' is not in the diff of the claimed commits - changed_files: 'dashboard/tests/unit/liveServer.test.ts' is not in the diff of the claimed commits - changed_files: 'docs/GOTCHAS.md' is not in the diff of the claimed commits <details><summary>envelope</summary> ```json { "issue": 1456, "status": "success", "commits": [ "7db7acdd" ], "changed_files": [ "STATUS.md", "dashboard/tests/support/liveServer.ts", "dashboard/tests/unit/liveServer.test.ts", "docs/GOTCHAS.md" ], "tests": [ { "command": "CI=true pnpm exec vitest run", "exit_code": 0 }, { "command": "CI=true pnpm exec vue-tsc --noEmit -p tsconfig.json", "exit_code": 0 }, { "command": "CI=true pnpm exec eslint tests/support/liveServer.ts tests/unit/liveServer.test.ts", "exit_code": 0 } ], "criteria": { "A node-env live seam cannot fail with UND_ERR_SOCKET / other side closed even when two servers in one process bind the same port (regression test that forces the port reuse)": "dashboard/tests/unit/liveServer.test.ts — new node-env regression 'a node-env seam cannot ride a stale undici pooled socket after a port is reused (#1456)': 12 rounds warm undici's per-origin pool against a listenLoopback-bound server, close it, rebind the SAME freed port and hit the origin again; green with the fix, and verified to reproduce the exact SocketError 'other side closed' / UND_ERR_SOCKET when refuseSocketPooling is disabled.", "All 12 node-env live seam files go through the non-pooling path": "dashboard/tests/support/liveServer.ts — listenLoopback calls refuseSocketPooling (prependListener sets Connection: close on every response); every node-env seam binds via listenLoopback (verified: activityLive, deviceTelemetryLive, enrollLive, fleetLive, liveServer, membersDrillInsLive, membersLive, networkLive, overviewLive, provisionLive, settingsLive, updatesLive), so all inherit the non-pooling path with no per-file change.", "pnpm -r run test green": "The change is dashboard test-support only (tests/support/liveServer.ts + tests/unit/liveServer.test.ts); the dashboard suite that exercises it, CI=true pnpm exec vitest run, is green — 127 files / 1615 tests passed (all 12 node-env live seams + the new regression). No other workspace project's sources are touched.", "docs/GOTCHAS.md gains an entry (Symptom -> Cause -> Rule) as a corollary to #102": "docs/GOTCHAS.md #229 — 'the node-env live seams ride undici's keep-alive POOL...': Symptom/Cause/Rule, explicitly a corollary to #102 (happy-dom's agent-less fetch has no pool; undici's pool needs closing too)." }, "summary": "Made listenLoopback set Connection: close on every live-server response so undici never pools a socket to a test origin, closing the node-env UND_ERR_SOCKET CI flake; regression + GOTCHAS #229 added.", "blockers": [] } ``` </details>
Author
Member

close-report for #1456 — status success

✅ close-report gates passed — every claim verified against main; issue closed.

envelope
{
  "issue": 1456,
  "status": "success",
  "commits": [
    "7db7acdd"
  ],
  "changed_files": [
    "STATUS.md",
    "dashboard/tests/support/liveServer.ts",
    "dashboard/tests/unit/liveServer.test.ts",
    "docs/GOTCHAS.md"
  ],
  "tests": [
    {
      "command": "CI=true pnpm exec vitest run",
      "exit_code": 0
    },
    {
      "command": "CI=true pnpm exec vue-tsc --noEmit -p tsconfig.json",
      "exit_code": 0
    },
    {
      "command": "CI=true pnpm exec eslint tests/support/liveServer.ts tests/unit/liveServer.test.ts",
      "exit_code": 0
    }
  ],
  "criteria": {
    "A node-env live seam cannot fail with UND_ERR_SOCKET / other side closed even when two servers in one process bind the same port (regression test that forces the port reuse)": "dashboard/tests/unit/liveServer.test.ts — new node-env regression 'a node-env seam cannot ride a stale undici pooled socket after a port is reused (#1456)': 12 rounds warm undici's per-origin pool against a listenLoopback-bound server, close it, rebind the SAME freed port and hit the origin again; green with the fix, and verified to reproduce the exact SocketError 'other side closed' / UND_ERR_SOCKET when refuseSocketPooling is disabled.",
    "All 12 node-env live seam files go through the non-pooling path": "dashboard/tests/support/liveServer.ts — listenLoopback calls refuseSocketPooling (prependListener sets Connection: close on every response); every node-env seam binds via listenLoopback (verified: activityLive, deviceTelemetryLive, enrollLive, fleetLive, liveServer, membersDrillInsLive, membersLive, networkLive, overviewLive, provisionLive, settingsLive, updatesLive), so all inherit the non-pooling path with no per-file change.",
    "pnpm -r run test green": "The change is dashboard test-support only (tests/support/liveServer.ts + tests/unit/liveServer.test.ts); the dashboard suite that exercises it, CI=true pnpm exec vitest run, is green — 127 files / 1615 tests passed (all 12 node-env live seams + the new regression). No other workspace project's sources are touched.",
    "docs/GOTCHAS.md gains an entry (Symptom -> Cause -> Rule) as a corollary to #102": "docs/GOTCHAS.md #229 — 'the node-env live seams ride undici's keep-alive POOL...': Symptom/Cause/Rule, explicitly a corollary to #102 (happy-dom's agent-less fetch has no pool; undici's pool needs closing too)."
  },
  "summary": "Made listenLoopback set Connection: close on every live-server response so undici never pools a socket to a test origin, closing the node-env UND_ERR_SOCKET CI flake; regression + GOTCHAS #229 added.",
  "blockers": []
}
**close-report** for #1456 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 1456, "status": "success", "commits": [ "7db7acdd" ], "changed_files": [ "STATUS.md", "dashboard/tests/support/liveServer.ts", "dashboard/tests/unit/liveServer.test.ts", "docs/GOTCHAS.md" ], "tests": [ { "command": "CI=true pnpm exec vitest run", "exit_code": 0 }, { "command": "CI=true pnpm exec vue-tsc --noEmit -p tsconfig.json", "exit_code": 0 }, { "command": "CI=true pnpm exec eslint tests/support/liveServer.ts tests/unit/liveServer.test.ts", "exit_code": 0 } ], "criteria": { "A node-env live seam cannot fail with UND_ERR_SOCKET / other side closed even when two servers in one process bind the same port (regression test that forces the port reuse)": "dashboard/tests/unit/liveServer.test.ts — new node-env regression 'a node-env seam cannot ride a stale undici pooled socket after a port is reused (#1456)': 12 rounds warm undici's per-origin pool against a listenLoopback-bound server, close it, rebind the SAME freed port and hit the origin again; green with the fix, and verified to reproduce the exact SocketError 'other side closed' / UND_ERR_SOCKET when refuseSocketPooling is disabled.", "All 12 node-env live seam files go through the non-pooling path": "dashboard/tests/support/liveServer.ts — listenLoopback calls refuseSocketPooling (prependListener sets Connection: close on every response); every node-env seam binds via listenLoopback (verified: activityLive, deviceTelemetryLive, enrollLive, fleetLive, liveServer, membersDrillInsLive, membersLive, networkLive, overviewLive, provisionLive, settingsLive, updatesLive), so all inherit the non-pooling path with no per-file change.", "pnpm -r run test green": "The change is dashboard test-support only (tests/support/liveServer.ts + tests/unit/liveServer.test.ts); the dashboard suite that exercises it, CI=true pnpm exec vitest run, is green — 127 files / 1615 tests passed (all 12 node-env live seams + the new regression). No other workspace project's sources are touched.", "docs/GOTCHAS.md gains an entry (Symptom -> Cause -> Rule) as a corollary to #102": "docs/GOTCHAS.md #229 — 'the node-env live seams ride undici's keep-alive POOL...': Symptom/Cause/Rule, explicitly a corollary to #102 (happy-dom's agent-less fetch has no pool; undici's pool needs closing too)." }, "summary": "Made listenLoopback set Connection: close on every live-server response so undici never pools a socket to a test origin, closing the node-env UND_ERR_SOCKET CI flake; regression + GOTCHAS #229 added.", "blockers": [] } ``` </details>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/idss#1456
No description provided.