Symptom
Master CI run 26397296711 failed on ubuntu-latest with:
FAIL test/cli/daemon.test.ts > bitsocial daemon webui
Daemon failed to start: listen EADDRINUSE: address already in use :::39138
27 of 28 test files passed; the bitsocial daemon webui suite died in beforeAll. macOS and Windows passed. Kubo bringup succeeded (Kubo IPFS API listening on 0.0.0.0:50189, Daemon is ready), then the PKC RPC bind to 39138 hit EADDRINUSE.
Root cause
test/cli/daemon.test.ts hardcodes RPC ports 11138, 19138, 29138, 39138, 49138, 59338, 59339. All of these sit inside Linux's default ephemeral port range (/proc/sys/net/ipv4/ip_local_port_range = 32768 60999).
Any outbound TCP connection on the runner — another vitest worker's kubo libp2p connection, GitHub Actions agent polls, npm registry traffic, system DNS, etc. — can have the kernel assign it one of those exact ports as its source port. While held, no one can listen() on it. On this run, something on the ubuntu-latest runner had :::39138 bound when the webui daemon tried to start.
The recent fail-fast PR (#47) is why the failure surfaces cleanly as Daemon failed to start: listen EADDRINUSE :::39138 rather than getting buried later. The flake itself predates that PR.
Why "use a high port" doesn't fix it
| OS |
Default ephemeral range |
| Linux |
32768 – 60999 |
| macOS |
49152 – 65535 |
| Windows (Vista+) |
49152 – 65535 |
The only window outside the ephemeral range on all three matrix OSes is roughly 1024 – 32767. That's where the already-safe ports in this file (9338, 9388, 9348) sit.
Fix
Move the seven hardcoded RPC ports into the safe 9148 – 9208 block (no collisions with any other test file or src/common-utils/defaults.ts):
| Current |
New |
Describe |
| 11138 |
9148 |
--pkcRpcUrl |
| 19138 |
9158 |
PKC_RPC_AUTH_KEY env var |
| 29138 |
9168 |
KUBO_RPC_URL env var |
| 39138 |
9178 |
webui (the failing one) |
| 49138 |
9188 |
kills kubo on shutdown |
| 59338 |
9198 |
DEBUG env var #1 |
| 59339 |
9208 |
DEBUG env var #2 |
Out of scope
The 50xxx Kubo ports in this file are also inside the Linux ephemeral range and could flake the same way, but haven't been observed to. Leaving for a follow-up.
Symptom
Master CI run 26397296711 failed on
ubuntu-latestwith:27 of 28 test files passed; the
bitsocial daemon webuisuite died inbeforeAll. macOS and Windows passed. Kubo bringup succeeded (Kubo IPFS API listening on 0.0.0.0:50189,Daemon is ready), then the PKC RPC bind to39138hitEADDRINUSE.Root cause
test/cli/daemon.test.tshardcodes RPC ports11138,19138,29138,39138,49138,59338,59339. All of these sit inside Linux's default ephemeral port range (/proc/sys/net/ipv4/ip_local_port_range=32768 60999).Any outbound TCP connection on the runner — another vitest worker's kubo libp2p connection, GitHub Actions agent polls, npm registry traffic, system DNS, etc. — can have the kernel assign it one of those exact ports as its source port. While held, no one can
listen()on it. On this run, something on the ubuntu-latest runner had:::39138bound when the webui daemon tried to start.The recent fail-fast PR (#47) is why the failure surfaces cleanly as
Daemon failed to start: listen EADDRINUSE :::39138rather than getting buried later. The flake itself predates that PR.Why "use a high port" doesn't fix it
The only window outside the ephemeral range on all three matrix OSes is roughly
1024 – 32767. That's where the already-safe ports in this file (9338,9388,9348) sit.Fix
Move the seven hardcoded RPC ports into the safe
9148 – 9208block (no collisions with any other test file orsrc/common-utils/defaults.ts):--pkcRpcUrlPKC_RPC_AUTH_KEY env varKUBO_RPC_URL env varwebui(the failing one)kills kubo on shutdownDEBUG env var#1DEBUG env var#2Out of scope
The 50xxx Kubo ports in this file are also inside the Linux ephemeral range and could flake the same way, but haven't been observed to. Leaving for a follow-up.