gnodet opened a new pull request, #30504:
URL: https://github.com/apache/camel/pull/30504
## Summary
Three consumers — `KnativeHttpConsumer`, `VertxWebsocketConsumer`, and
`VertxWebsocketClientConsumer` — held a Vert.x worker thread for the entire
duration of the route. This PR fixes all three by applying the same
async-processor pattern that was introduced for `VertxPlatformHttpConsumer` in
CAMEL-27217 (commit 5b3fa2df443c).
## Root Cause
Each consumer dispatched the route via `executeBlocking(() -> {
getProcessor().process(exchange); return null; })`. Because
`getProcessor().process(exchange)` is the synchronous overload, it blocks in
`DefaultAsyncProcessorAwaitManager.await()` until the route completes. The
worker thread is therefore held for the entire route.
A route that calls `vertx-http` (or any async producer) on the same Vert.x
instance needs a worker thread to complete each outbound call. With as many
requests in flight as worker threads, every worker waited for an outbound call
to complete, every outbound call waited for a free worker, and nothing made
progress.
## Fix
All three consumers now use the two-argument
`getAsyncProcessor().process(exchange, callback)` form inside
`executeBlocking`. The worker thread starts the route and returns as soon as
the route delegates asynchronously; the callback fires `context.runOnContext(v
-> done.tryComplete())` to complete the promise on the original Vert.x context,
which then writes the response (for HTTP) or releases the exchange (for
WebSocket):
```java
Context context = vertx.getOrCreateContext();
Promise<Void> done = Promise.promise();
vertx.executeBlocking(() -> {
createUoW(exchange);
getAsyncProcessor().process(exchange, doneSync -> context.runOnContext(v
-> done.tryComplete()));
return null;
}, false).onFailure(done::tryFail);
done.future().onComplete(result -> { /* write response / cleanup */ });
```
## Tests
- **`KnativeHttpSharedVertxWorkerPoolTest`**: creates a Vert.x with 2
workers and a knative-http route whose async step holds until 2 requests all
arrive. With the old code, both workers would deadlock waiting for each other.
With the fix, all 2 requests reach the step concurrently and complete.
- **`VertxWebsocketSharedVertxWorkerPoolTest`**: same pattern for
`VertxWebsocketConsumer`. Sends 2 WebSocket messages concurrently via a shared
Vert.x and asserts all reach the async step without deadlock.
Both new tests cover `VertxWebsocketClientConsumer` indirectly through the
shared `processExchange` structure; the existing
`VertxWebSocketSlowClientConsumerTest` also runs and passes.
## Related
- CAMEL-27217 / commit 5b3fa2df443c: same fix for
`VertxPlatformHttpConsumer` (the reference implementation)
Fixes CAMEL-27294
---
_Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_
--
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]