This is an automated email from the ASF dual-hosted git repository.

apupier pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 631fa9c687084b655da2495642fd964491b3502a
Author: smjain <[email protected]>
AuthorDate: Wed Sep 23 16:45:51 2026 +0530

    CAMEL-24924: camel-core - Failover load balancer without processors should 
complete the exchange
    
    A failover load balancer with no processors never called the callback, so
    the caller waited forever. In the default mode it failed with a
    NullPointerException when copying the result of the (missing) last attempt,
    and in round robin or sticky mode with an ArrayIndexOutOfBoundsException.
    Both happened in a task on the reactive executor, so nothing reached the
    exchange.
    
    It now completes the exchange straight away, as QueueLoadBalancer and
    TopicLoadBalancer already do when they have no processors.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../loadbalancer/FailOverLoadBalancer.java         |  5 ++
 .../FailOverLoadBalanceNoProcessorsTest.java       | 59 ++++++++++++++++++++++
 2 files changed, 64 insertions(+)

diff --git 
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java
 
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java
index b16e4d80332e..e930e06bd1a2 100644
--- 
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java
+++ 
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java
@@ -165,6 +165,11 @@ public class FailOverLoadBalancer extends 
LoadBalancerSupport implements Traceab
     @Override
     public boolean process(final Exchange exchange, final AsyncCallback 
callback) {
         AsyncProcessor[] processors = doGetProcessors();
+        if (processors.length == 0) {
+            // no processors but indicate we are done (same as the other load 
balancers)
+            callback.done(true);
+            return true;
+        }
         exchange.getContext().getCamelContextExtension().getReactiveExecutor()
                 .schedule(new State(exchange, callback, processors)::run);
         return false;
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/FailOverLoadBalanceNoProcessorsTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/FailOverLoadBalanceNoProcessorsTest.java
new file mode 100644
index 000000000000..0dc4b7c09ed1
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/FailOverLoadBalanceNoProcessorsTest.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor;
+
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * A failover load balancer without any processors should complete the 
exchange like the other load balancers do,
+ * instead of never calling the callback.
+ */
+public class FailOverLoadBalanceNoProcessorsTest extends ContextTestSupport {
+
+    @ParameterizedTest
+    @ValueSource(strings = { "direct:default", "direct:roundRobin", 
"direct:sticky", "direct:roundRobinSticky" })
+    public void testNoProcessors(String uri) throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+
+        // use async send so the test fails instead of hanging if the exchange 
is never completed
+        Future<String> reply = template.asyncRequestBody(uri, "Hello World", 
String.class);
+        assertEquals("Hello World", reply.get(5, TimeUnit.SECONDS));
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                
from("direct:default").loadBalance().failover().end().to("mock:result");
+                from("direct:roundRobin").loadBalance().failover(-1, false, 
true).end().to("mock:result");
+                from("direct:sticky").loadBalance().failover(-1, false, false, 
true).end().to("mock:result");
+                from("direct:roundRobinSticky").loadBalance().failover(-1, 
false, true, true).end().to("mock:result");
+            }
+        };
+    }
+
+}

Reply via email to