Fix flaky NettyClientAlpnTest by retrying on port-bind race conditions#7142
Conversation
Weird. Can we just fix the server so that it doesn't do this weird allocate then free dance? Forcing every test that uses |
Done, added the fix to get the port right before the start. |
|
This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one. |
Motivation and Context
NettyClientAlpnTestintermittently fails withIOException: Failed to bind to 0.0.0.0:<port>.Root cause:
BaseMockServer.getUnusedPort()opens aServerSocket(0)to get a free port number, then closes the socket before the port is actually used. Between that close and the laterserver.start()bind, the port is unowned and can be taken by another process on the CI host (example an outbound connection's ephemeral source port). When that happens, Jetty's bind fails and the test errors out, unrelated to any ALPN/HTTP2 code being tested.Modifications
MockH2Server.java: connectors now bind to port 0, so the kernel assigns a free port atomically at bind time and the allocate-then-free race is gone.start()reads the actual ports back viaconnector.getLocalPort().BaseMockServer.java: removedgetUnusedPort()and the constructor that pre-allocated ports; it now only holds the port fields and URI helpers.NettyClientAlpnTest.java: no functional change, tests stay plain@Test.Testing
Verified by forcing a real port collision: retry fired for 3 attempts as configured, then passed once the port was free.
License