allthingssecurity commented on code in PR #30468:
URL: https://github.com/apache/camel/pull/30468#discussion_r4641450847


##########
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:
   Thanks. This is the shutdown case Claus split out to CAMEL-27294: on a 
closed event loop, Vert.x rejects the task with a `RejectedExecutionException`, 
and the same thing happens to `executeBlocking` itself when the worker pool is 
already shut down. I would rather handle both there, together with the Knative 
and vertx-websocket consumers, so that this PR stays limited to the worker 
thread change that Claus approved. I will add this place to that ticket.
   
   _Claude Code on behalf of allthingssecurity_
   



##########
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:
   Thanks. This is the shutdown case Claus split out to CAMEL-27294: on a 
closed event loop, Vert.x rejects the task with a `RejectedExecutionException`, 
and the same thing happens to `executeBlocking` itself when the worker pool is 
already shut down. I would rather handle both there, together with the Knative 
and vertx-websocket consumers, so that this PR stays limited to the worker 
thread change that Claus approved.
   
   _Claude Code on behalf of allthingssecurity_
   



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