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
Labels
No labels
agent-blocked
agent-working
autopilot
bug
deferred
deploy-pending
enhancement
landing-pr
model-haiku
model-opus
model-sonnet
needs-design
needs-info
needs-triage
no-triage
out-of-scope
priority
ready-for-agent
ready-for-human
ready-for-session
rehearsal-183
snapshot-pending
standing-drive
wayfinder:grilling
wayfinder:map
wayfinder:prototype
wayfinder:research
wayfinder:task
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Matou/idss#1456
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
CI run 22664 (
ci/ seam) went red on main with ONE test out of 1611: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.tsruns in vitest'snodeenvironment, so itsround-trips go over Node's global
fetch(undici), which pools keep-alivesockets per origin (
http://127.0.0.1:<port>). That is the difference fromGOTCHAS #102 / #888, whose cure was written for happy-dom's
fetch— whichopens a one-off socket per request (
agent: false, no keep-alive) andtherefore has no pool to go stale.
The exposure:
listenLoopback()(dashboard/tests/support/liveServer.ts) draws arandom port from the 20000–32767 band for every live server.
afterEachcallscloseLiveServer(server). Outside happy-domhappyDomApi()isundefined, so it degrades to a bareserver.close()—it drains nothing on the undici side, and undici's pooled socket for that
origin is left in the global dispatcher.
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: 1199on asocket 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):Same error, same shape, same accumulated-bytes signature.
Scope — this is a class, not one file
12 live-server seam files run in the
nodeenv and therefore use realundici keep-alive (the other 12 are
happy-domand 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 1red 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:
Suggested shape: have
dashboard/tests/support/liveServer.tsown the responsewrite (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 noorigin 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: closeis thesmaller change and is immune to port reuse between processes too.
Belt-and-braces worth considering in the same pass: make
closeLiveServer'snode-env path explicit rather than a silent degrade, so the next person reading
it sees that it drains nothing.
Acceptance
UND_ERR_SOCKET/other side closedeven when two servers in one process bind the same port(regression test in
liveServerTeardown.test.tsorliveServer.test.tsthat forces the port reuse).
pnpm -r run testgreen.docs/GOTCHAS.mdgains an entry (Symptom → Cause → Rule) as a corollaryto #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 closedtoo.
Filed by the swarm healer. Incident: run 22664, signature
86bc15a09f6e,heal run
heal-Matou-idss-1789232956-1357341.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)
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=22596
(automated multi-host claim — lowest live claim id works this ticket)
close-report for #1456 — status
success⛔ close-report gates REFUSED this close — the following claims did not verify:
7db7acddis not reachable from origin/main (not landed)envelope
close-report for #1456 — status
success✅ close-report gates passed — every claim verified against main; issue closed.
envelope