apupier opened a new pull request, #31011:
URL: https://github.com/apache/camel/pull/31011

   ## Description
   
   Fixes the flaky `HttpClientRouteSpringTest` (JIRA: CAMEL-27545), which 
sometimes failed in `setupResources()` with:
   
   ```
   java.lang.RuntimeException: java.net.BindException: Address already in use
        at io.undertow.Undertow.start(Undertow.java:254)
        at 
org.apache.camel.component.servlet.ServletCamelRouterTestSupport.setupResources(ServletCamelRouterTestSupport.java:65)
   ```
   
   ### Root cause
   
   `ServletCamelRouterTestSupport` reserved its port with 
`AvailablePortFinder.find()` in a field initializer, i.e. when the test 
instance is created, long before Undertow binds it in `setupResources()`. 
`AvailablePortFinder` only probes a free port and records it in a registry of 
the current JVM, it does not keep it bound. Another surefire fork or process 
could therefore take the port in that window.
   
   ### Fix
   
   Let Undertow bind port `0` so the OS picks a free port at bind time, and 
read the bound port back from `server.getListenerInfo()`. This removes the 
window between finding and using the port, and the now-unneeded 
`AvailablePortFinder` extension. The change is limited to the test support 
class, which is shared by all `camel-servlet` tests.
   
   ### Testing
   
   `mvn test -pl components/camel-servlet`: 133 tests, 0 failures (2 skipped, 
unchanged). The flakiness depends on another process stealing the port, so it 
cannot be reproduced deterministically; the fix removes the race instead.
   
   ---
   _Claude Code-style attribution: this PR was prepared by IBM Bob 2.2.1 (AI) 
on behalf of @apupier._


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to