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
tests: five serve route tests fail on a front-port collision instead of retrying (check-then-use race, CI flake) #1444
The port is released before serve binds it, and serve launches its backends (each on a free_port(), which also releases before the child binds) before it binds its own front port (app/serve.cpp: launch_for(... free_port()) runs before bind_to_port(o.host, o.port)). Under ctest -j, any other serve or backend on the runner can take the port in that window.
Seen on CI:ci run 42468438033 (PR #1437, a one-string change to onnx/ort_run.cpp): hybrid_route passed its first 27 checks, then failed with FAIL: hybrid_route: could not bind a port 45419 (Address already in use). The previous head and main were green.
Affected (the same block, copied): tests/hybrid_route.sh, tests/hybrid_kvshare_route.sh, tests/hybrid_e2e.sh, tests/hrx_cwsr_route.sh, tests/device_route.sh. Each already detects the collision ("a port collision, not a defect in what this test checks") but exits 1, so a runner-side race turns CI red.
Fix: when the bind check fires, reap that serve and retry the same start on a new port, up to 3 tries, printing a note line. Only a third consecutive collision fails. Test-only; serve's startup order is unchanged.
Claiming this — lane pi-i669, unowned (0 comments, no board entry) under the standing loop. It is the class I spent last night on from the other side: a harness that reports the wrong verdict about the code under test (I shipped a fix yesterday for a device test binary that selected zero cases and exited 0, and I lost four GPU arms today to a squatted port, so the check-then-use shape is very familiar).
Plan, before touching anything: (1) read the five blocks and confirm they are byte-identical apart from the test name, so one fix covers five and no test silently keeps the old block; (2) reproduce the collision deterministically rather than waiting for CI — hold the chosen port in a background listener between the pick and the launch, which turns the race into a guaranteed collision, and assert the current script fails; (3) make the launch retry: a bounded re-pick on port-collision only, with the collision still distinguished from a real defect, and the retry counted in the log so a genuine bind problem cannot hide behind it; (4) re-run with the port held to show the retry passing, and once without any holder to show the normal path unchanged. If the five blocks are not identical I will fix them where they differ rather than normalising them for the sake of it.
Checked the three scripts I defered in #1446, and they are not the same state as the five — worth having on the record before someone assumes the class is finished:
So the five now retry a collision they already named, while these three would fail with a generic "serve did not answer /health" and no hint that the cause was a port race — a worse failure mode, since the reader has to work out that nothing about their feature is broken. grep -c 'could not bind a port' is 0 in all three.
Finishing the class is the same change plus the detection the five already have (three files, ~20 lines each, same shape as #1446), and I am not doing it unprompted because #1444 names the five and #1446 is already READY — folding three more files in now would make a READY diff move under the reviewer. Two ways to take it, and either is fine by me:
The isolated retry evidence in #1446 applies unchanged; what the three need on top is simply the grep -qiE 'EADDRINUSE|address already in use|cannot listen on' guard before the fail — and because they do not have it today, their first run would also tell us whether the race even fires there (anchor_rerun.sh polls for up to an hour, so it is the most likely to be hit on a loaded runner).
Scope, found while proving the fix: 24 test scripts pick a front port with the same release-then-bind one-liner. The five named above are the ones that already detect the collision; the PR for this issue fixes those (retry on a new port, fail on a third collision in a row).
The other 19 have no collision check, so a loss there shows up as a generic "did not answer" failure, not a port message: anchor_rerun, greedy_shortcut, hrx_cpu_weight_parity, hrx_runtime_route, laya_gguf_route, laya_models_e2e, laya_route_e2e, mem_admit_route, metrics_serve, npu_repack_path, parallel_args, pm_laya_route, pm_route, prism_route, recipes_route (3 picks), serve_e2e, smoke_serve (3 picks), watchdog_serve (.sh), and kvshare_fd_handoff.py.
For those, copying the loop 19 more times is the wrong shape. The follow-up should be one shared helper, or serve --port 0 printing the port it bound, which removes the race instead of retrying around it. Not in the first PR.
Activity
bong-water-water-bong commentedon Nov 8, 2026
Claiming this — lane
pi-i669, unowned (0 comments, no board entry) under the standing loop. It is the class I spent last night on from the other side: a harness that reports the wrong verdict about the code under test (I shipped a fix yesterday for a device test binary that selected zero cases and exited 0, and I lost four GPU arms today to a squatted port, so the check-then-use shape is very familiar).Plan, before touching anything: (1) read the five blocks and confirm they are byte-identical apart from the test name, so one fix covers five and no test silently keeps the old block; (2) reproduce the collision deterministically rather than waiting for CI — hold the chosen port in a background listener between the pick and the launch, which turns the race into a guaranteed collision, and assert the current script fails; (3) make the launch retry: a bounded re-pick on port-collision only, with the collision still distinguished from a real defect, and the retry counted in the log so a genuine bind problem cannot hide behind it; (4) re-run with the port held to show the retry passing, and once without any holder to show the normal path unchanged. If the five blocks are not identical I will fix them where they differ rather than normalising them for the sake of it.
tests: the five serve route tests retry a taken port instead of faili…
bong-water-water-bong commentedon Nov 8, 2026
Checked the three scripts I defered in #1446, and they are not the same state as the five — worth having on the record before someone assumes the class is finished:
tests/anchor_rerun.shbind(0)then launch)EADDRINUSE/cannot listen oncheck at alltests/greedy_shortcut.shtests/laya_gguf_route.shSo the five now retry a collision they already named, while these three would fail with a generic "serve did not answer /health" and no hint that the cause was a port race — a worse failure mode, since the reader has to work out that nothing about their feature is broken.
grep -c 'could not bind a port'is 0 in all three.Finishing the class is the same change plus the detection the five already have (three files, ~20 lines each, same shape as #1446), and I am not doing it unprompted because #1444 names the five and #1446 is already READY — folding three more files in now would make a READY diff move under the reviewer. Two ways to take it, and either is fine by me:
The isolated retry evidence in #1446 applies unchanged; what the three need on top is simply the
grep -qiE 'EADDRINUSE|address already in use|cannot listen on'guard before the fail — and because they do not have it today, their first run would also tell us whether the race even fires there (anchor_rerun.shpolls for up to an hour, so it is the most likely to be hit on a loaded runner).bong-water-water-bong commentedon Nov 8, 2026
Scope, found while proving the fix: 24 test scripts pick a front port with the same release-then-bind one-liner. The five named above are the ones that already detect the collision; the PR for this issue fixes those (retry on a new port, fail on a third collision in a row).
The other 19 have no collision check, so a loss there shows up as a generic "did not answer" failure, not a port message:
anchor_rerun,greedy_shortcut,hrx_cpu_weight_parity,hrx_runtime_route,laya_gguf_route,laya_models_e2e,laya_route_e2e,mem_admit_route,metrics_serve,npu_repack_path,parallel_args,pm_laya_route,pm_route,prism_route,recipes_route(3 picks),serve_e2e,smoke_serve(3 picks),watchdog_serve(.sh), andkvshare_fd_handoff.py.For those, copying the loop 19 more times is the wrong shape. The follow-up should be one shared helper, or
serve --port 0printing the port it bound, which removes the race instead of retrying around it. Not in the first PR.serve: --port 0 reports the port the kernel gave it, so a test can st…
tests: npu_repack_path takes a port nobody uses; census moves for the…
tests: read back the port llama-server bound, and migrate the last tw…
tests: read back the port llama-server bound, and migrate the last tw…