gnodet-bot commented on code in PR #30468:
URL: https://github.com/apache/camel/pull/30468#discussion_r4641037081
##########
components/camel-platform-http-vertx/src/main/java/org/apache/camel/component/platform/http/vertx/VertxPlatformHttpConsumer.java:
##########
@@ -425,10 +427,35 @@ private void handleFailure(Exchange exchange,
RoutingContext ctx, Throwable fail
handleExchangeComplete(exchange);
}
- private Object processExchange(Exchange exchange) throws Exception {
- createUoW(exchange);
- getProcessor().process(exchange);
- return null;
+ /**
+ * Routes the exchange, starting on a thread of the Vert.x worker pool, as
the first steps of the route may block.
+ * The returned future completes on the context of the request, when the
route is done.
+ * <p>
+ * With the endpoint option {@code synchronous=true} the worker thread
runs the route with the synchronous
+ * processor, so it is held until the route completes, and the worker pool
bounds the requests in flight.
+ * <p>
+ * Otherwise (the default) the route runs with the asynchronous processor,
and the worker thread is not held until
+ * the route completes: when the route continues on another thread, such
as a vertx-http producer that completes its
+ * exchange on a worker thread of the same Vert.x, a worker thread waiting
for the route could be the one that the
+ * other thread needs, and with every worker thread waiting no request
would ever complete.
+ */
+ private Future<Void> processExchange(Vertx vertx, Exchange exchange) {
+ if (getEndpoint().isSynchronous()) {
+ return vertx.executeBlocking(() -> {
+ createUoW(exchange);
+ getProcessor().process(exchange);
+ return null;
+ }, false);
+ }
+
+ 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);
Review Comment:
If `context.runOnContext` throws (e.g., Vert.x is shutting down and its
event loop is closed), the exception escapes the `AsyncCallback` and `done` is
never completed — the HTTP response for this in-flight request leaks until the
connection times out or Vert.x force-closes it. The `onFailure(done::tryFail)`
guard only covers exceptions from `executeBlocking`'s callable; it does not
intercept a throw from inside the callback.
A defensive try-catch keeps the promise lifecycle airtight:
```suggestion
vertx.executeBlocking(() -> {
createUoW(exchange);
getAsyncProcessor().process(exchange, doneSync -> {
try {
context.runOnContext(v -> done.tryComplete());
} catch (Exception e) {
done.tryComplete();
}
});
return null;
}, false).onFailure(done::tryFail);
```
--
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]