Skip to content

test(station-host): bind mesh sockets on :0 in e2e and peers tests to remove UDP port TOCTOU - #10512

Open
CommaBot wants to merge 1 commit into
mainfrom
ci/wave7b-udp-port-zero
Open

CommaBot wants to merge 1 commit into
mainfrom
ci/wave7b-udp-port-zero

Conversation

@CommaBot

@CommaBot CommaBot commented Dec 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #10488 removing all remaining freeUdpPort() / UDP probe-close-rebind TOCTOU allocations across pion/station-host/tests/e2e/ and pion/station-host/tests/peers.mjs:

  • pion/station-host/tests/e2e/fault-move-and-connects.test.ts & pion/station-host/tests/e2e/fault-runtimes-and-lend.test.ts:
    • Replace freeUdpPort() with STILLFAIL_MESH_BIND_ADDR=127.0.0.1:0, parse each launched station's OS-assigned port via meshPort(), push updated peer addresses via pushAll() once both stations are online and connected at the mock control plane, and wait for both stations' mesh/cloud.json peers to reflect the bound ports.
  • pion/station-host/tests/e2e/live-p5-3.test.ts:
    • Replace freeUdpPort() by launching beta first on 127.0.0.1:0, reading its bound port via meshPort(), writing alpha's cloud.json with beta's real port, and launching alpha on 127.0.0.1:0.
  • pion/station-host/tests/e2e/cross-engine-harness.ts, cross-engine-move.test.ts, cross-engine-move-items.test.ts:
    • Add controlPlane().pushPeers() and Twins.wirePeers(stations) + Twins.station(kind, { peer: true }) so both Node and Pion stations bind 127.0.0.1:0 and learn each other's real ports through the control plane; remove freeUdpPort().
  • pion/station-host/tests/peers.mjs:
    • Remove both createSocket("udp4") probe-close-rebind sites (initial boot, beta restart, and single-station SIGTERM test); bind 127.0.0.1:0, capture mesh listening from stderr while forwarding stderr to process.stderr, push updated state to all open presence sockets, and wait for live peers' mesh/cloud.json convergence.

Verification

  • node --check passed on all 7 modified .ts/.mjs files
  • git grep -n "freeUdpPort" -- pion/ station/: 0 matches remaining
  • node scripts/agents-paths.ts: passed
  • CI pion-station-main runs all affected suites (station-host-e2e moves, copies, live-peers, and station-host-engines)

Models used: Gemini 4 Neon, Claude Opus 5.5 (independent review).
Test frameworks: Node node:test, pion-station-main e2e & cross-engine CI suites.


Proof this PR
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

… remove UDP port TOCTOU

Eliminate all remaining freeUdpPort() / probe-close-rebind UDP port TOCTOU races across pion/station-host/tests/e2e/ and pion/station-host/tests/peers.mjs (same root cause fixed for station/test/ in #10488):
- fault-move-and-connects.test.ts & fault-runtimes-and-lend.test.ts: bind STILLFAIL_MESH_BIND_ADDR=127.0.0.1:0, parse OS-assigned port via meshPort(), push peers over the mock control plane (pushAll()), and wait for cloud.json peers convergence.
- live-p5-3.test.ts: start beta on 127.0.0.1:0 first, read its bound port via meshPort(), then write alpha's cloud.json with beta's real address and start alpha on 127.0.0.1:0.
- cross-engine-harness.ts, cross-engine-move.test.ts & cross-engine-move-items.test.ts: add controlPlane().pushPeers() and Twins.wirePeers() with station(..., { peer: true }) binding 127.0.0.1:0.
- peers.mjs: bind 127.0.0.1:0 in both tests; in test 1 parse each booted/restarted host's bound mesh port from stderr, push updated peers via the presence WebSocket, and wait for live peers' cloud.json convergence.

Co-authored-by: zuozijian <zuozijian@cue.surf>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants