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

   # Description
   
   **JIRA:** https://issues.apache.org/jira/browse/CAMEL-24762
   
   `CoAPComponentTLSTest` failed rarely on CI (3 times in ~2,000 builds over 90 
days) with `None of the server endpoints could be started`, and once it failed, 
the other tests in the class and the reruns failed the same way.
   
   The test reserves 8 static ports with `AvailablePortFinder.find()`, and all 
routes start a CoAP server on them for each test. `AvailablePortFinder` checks 
a port by binding a `ServerSocket`, i.e. TCP only, but `coaps` runs DTLS over 
UDP and the server binds a UDP socket on all interfaces (`new 
InetSocketAddress(port)`). A port that is free for TCP can still be taken for 
UDP, and then the server cannot bind. Because the ports are static, the same 
blocked port is reused by every test in the class and by the reruns, which 
matches the failure pattern. The visible failures in Develocity also ran on the 
same CI host.
   
   This PR adds a `findUdpPort()` helper to `CoAPTestSupport` that takes ports 
from `AvailablePortFinder` and only returns one that can also be bound with a 
`DatagramSocket`. Rejected ports stay reserved until a free one is found, then 
are released. It is used for:
   - the 8 ports in `CoAPComponentTLSTestBase` (the flaky test)
   - the shared `PORT` in `CoAPTestSupport` and `coapport` in 
`CoAPRestComponentTestBase`, which bind UDP servers the same way
   
   Ports that are TCP-only (`TCP_PORT` in `CoAPComponentTest`) or deliberately 
unused (`CoAPProducerNoResponseTest`) are left as they are.
   
   I could not reproduce the failure locally given how rare it is, so this 
addresses the most likely cause rather than a confirmed one. The server cleanup 
looked fine (servers are tracked before start and stopped in `doStop`), and 
there is still a small window between the check and the bind, as with any port 
finder. A UDP-aware option in `AvailablePortFinder` itself could be a broader 
follow-up for other UDP-based tests.
   
   Tests: camel-coap 76/76 passed locally.
   
   AI assistance: investigation and changes were done with help from Claude 
(Anthropic). I reviewed and verified the changes and tests locally.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   
   - [x] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
   
   Built and tested camel-coap; test-only change, no generated changes.
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.


-- 
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