Dhairya-007 opened a new pull request, #29681:
URL: https://github.com/apache/camel/pull/29681

   ## Problem
   
   `VertxComponent.doStart` builds a clustered Vert.x asynchronously and waits 
on a latch, because — as the comment in that method says — *"we want to wait 
for the eventbus to be ready before we are in started state"*. Two things made 
the wait ineffective:
   
   ```java
   if (latch.getCount() > 0) {
       LOG.info("Waiting for EventBus to be ready using {} sec as timeout", 
timeout);
       latch.await(timeout, TimeUnit.SECONDS);   // result discarded
   }
   ```
   
   ```java
   vertxFactory.buildClustered().onComplete(event -> {
       if (event.cause() != null) {
           LOG.warn("Error creating Clustered Vertx {}:{} due {}", host, port, 
event.cause().getMessage(), event.cause());
       } else if (event.succeeded()) {
           vertx = event.result();
       }
       latch.countDown();
   });
   ```
   
   - `CountDownLatch.await(timeout, unit)` returns `false` on timeout, and that 
is thrown away.
   - A failed build only produces a warning, and the latch is counted down 
anyway.
   
   In both cases `vertx` stays `null` and the component reaches the **started** 
state regardless. The failure then surfaces much later as a 
`NullPointerException` from whichever endpoint, producer or consumer 
dereferences `getVertx()` first — with nothing in that stack trace pointing at 
the cluster that never came up. The configured `timeout` option effectively 
does nothing but delay the start.
   
   ## Fix
   
   - Throw when the bounded wait times out, naming the timeout.
   - Capture the build failure and rethrow it with its cause attached, instead 
of only logging it.
   - Guard against a completion that neither failed nor produced an instance.
   
   Starting with a `vertx` instance set on the component, and the non-clustered 
path, are untouched.
   
   ## Tests
   
   New `VertxStartupTest` drives `doStart` through a small `VertxBuilder` test 
double whose `buildClustered()` returns whatever the test wants:
   
   - `shouldFailWhenTheEventBusIsNotReadyWithinTheTimeout` — a future that 
never completes, with `timeout=1`; the start has to fail and `getVertx()` stay 
null.
   - `shouldFailWhenBuildingTheClusteredVertxFails` — a failed future; the 
start has to fail and carry the original cause.
   
   Both pass on `main` only in the sense that the component starts happily with 
no Vert.x at all — they fail there on the `assertThrows`.


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