Commit 39c79bc
committed
Use deterministic port allocation in integration tests
Integration tests allocate listening ports for test nodes by binding
to 127.0.0.1:0, reading the OS-assigned port, then immediately
dropping the socket. Later, Node::start() tries to bind to that same
port. This has two problems:
Parallel test collisions: with 35 tests running concurrently, each
creating 2-4 nodes with 2 ports each, the OS can reassign a freed
port to another test's node before the original node calls start().
This is a classic TOCTOU race. In CI, it caused ~50% of Rust test
runs to fail with InvalidSocketAddress, always exactly one random
test per run.
Restart instability: when a test stops and restarts a node, the port
is released during stop() and must be re-acquired during start().
Another test's node can grab it in between. The peer store still has
the old address, so auto-reconnection also fails.
Both problems are inherent to any scheme that allocates a port and
later releases it. The only way to guarantee a port stays yours is
to never release it, or to never share the port space.
A deterministic atomic counter starting at a fixed base port (20000)
solves both problems: each fetch_add returns a unique value, so no
two nodes in the same process ever get the same port, and ports are
stable across restarts because the same node keeps the same config.
There is no external contention because CI runners are isolated.
AI tools were used in preparing this commit.1 parent a555133 commit 39c79bc
2 files changed
+14
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
268 | 269 | | |
269 | 270 | | |
270 | 271 | | |
271 | | - | |
272 | | - | |
273 | | - | |
| 272 | + | |
274 | 273 | | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
282 | 280 | | |
283 | 281 | | |
284 | 282 | | |
| |||
304 | 302 | | |
305 | 303 | | |
306 | 304 | | |
307 | | - | |
| 305 | + | |
308 | 306 | | |
309 | 307 | | |
310 | 308 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
| 24 | + | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
1429 | 1429 | | |
1430 | 1430 | | |
1431 | 1431 | | |
1432 | | - | |
| 1432 | + | |
1433 | 1433 | | |
1434 | | - | |
| 1434 | + | |
1435 | 1435 | | |
1436 | 1436 | | |
1437 | 1437 | | |
| |||
1441 | 1441 | | |
1442 | 1442 | | |
1443 | 1443 | | |
1444 | | - | |
| 1444 | + | |
1445 | 1445 | | |
1446 | 1446 | | |
1447 | 1447 | | |
| |||
0 commit comments