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

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


The following commit(s) were added to refs/heads/main by this push:
     new f945c7f8a510 CAMEL-25484: camel-core - an exchange cut off by a route 
stop or reload is logged as one WARN line (#27599)
f945c7f8a510 is described below

commit f945c7f8a51045472595928ec41eac043c740a91
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Oct 9 08:40:24 2026 +0200

    CAMEL-25484: camel-core - an exchange cut off by a route stop or reload is 
logged as one WARN line (#27599)
    
    When a route stop or a dev mode reload times out its graceful shutdown, an
    in-flight exchange is cut off with a RejectedExecutionException ("its route
    is being stopped or reloaded", CAMEL-25365). The error handler logged it as
    a failed delivery: ERROR, "Exhausted after delivery attempt", message
    history and stack trace, although nothing in the route failed and a file
    consumer delivers the message again after the reload.
    
    Both error handler tasks now log it as one line at most WARN. A forced
    CamelContext stop and every other failure are logged as before; the
    exception on the exchange is unchanged.
    
    
    Claude-Session: https://claude.ai/code/session_01STT6whBgK1AqsSsUKrnE8m
    
    Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
---
 .../errorhandler/RedeliveryErrorHandler.java       | 37 ++++++++-
 .../errorhandler/RouteStopCutOffLogTest.java       | 95 ++++++++++++++++++++++
 .../ROOT/pages/camel-4x-upgrade-guide-4_23.adoc    | 10 +++
 3 files changed, 141 insertions(+), 1 deletion(-)

diff --git 
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
 
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
index a6728ba7fe36..e7494304853c 100644
--- 
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
+++ 
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java
@@ -985,6 +985,10 @@ public abstract class RedeliveryErrorHandler extends 
ErrorHandlerSupport
                 e = exchange.getProperty(ExchangePropertyKey.EXCEPTION_CAUGHT, 
Exception.class);
             }
 
+            if (logCutOffByRouteStop(exchange, e, logger.getLevel())) {
+                return;
+            }
+
             if (exchange.isRollbackOnly() || exchange.isRollbackOnlyLast()) {
                 String msg = "Rollback " + ExchangeHelper.logIds(exchange) + 
failureOrigin(exchange);
                 Throwable cause = exchange.getException() != null
@@ -1910,6 +1914,10 @@ public abstract class RedeliveryErrorHandler extends 
ErrorHandlerSupport
                 e = exchange.getProperty(ExchangePropertyKey.EXCEPTION_CAUGHT, 
Exception.class);
             }
 
+            if (!newException && logCutOffByRouteStop(exchange, e, 
newLogLevel)) {
+                return;
+            }
+
             if (newException) {
                 // log at most WARN level
                 if (newLogLevel == LoggingLevel.ERROR) {
@@ -2213,10 +2221,37 @@ public abstract class RedeliveryErrorHandler extends 
ErrorHandlerSupport
      * {@code RejectedExecutionException - null}, which looks like a fault in 
the route, while it is a route stop or a
      * dev mode reload cutting the exchange off (CAMEL-25365).
      */
+    static final String ROUTE_STOPPING_REASON = "The exchange cannot continue: 
its route is being stopped or reloaded";
+
     String notAllowedReason() {
         return shutdownStrategy.isForceShutdown()
                 ? "The exchange cannot continue: its route was forced to shut 
down, as the graceful shutdown timed out"
                   + " while it was in flight (the CamelContext is being 
stopped)"
-                : "The exchange cannot continue: its route is being stopped or 
reloaded";
+                : ROUTE_STOPPING_REASON;
+    }
+
+    /**
+     * Whether the failure is an exchange cut off by a route stop or a dev 
mode reload (not a forced CamelContext stop):
+     * nothing in the route failed, and a consumer that rolls back, such as 
file, delivers it again (CAMEL-25484).
+     */
+    static boolean isCutOffByRouteStop(Throwable e) {
+        return e instanceof RejectedExecutionException && 
ROUTE_STOPPING_REASON.equals(e.getMessage());
+    }
+
+    /**
+     * Logs an exchange that a route stop or a dev mode reload cut off as one 
line at most WARN, without the message
+     * history and stack trace of a failure, as nothing in the route failed 
(CAMEL-25484).
+     *
+     * @return whether the exchange was cut off, and so is logged
+     */
+    boolean logCutOffByRouteStop(Exchange exchange, Throwable e, LoggingLevel 
level) {
+        if (!isCutOffByRouteStop(e) || exchange.isRollbackOnly() || 
exchange.isRollbackOnlyLast()) {
+            return false;
+        }
+        logger.log("Exchange cut off " + ExchangeHelper.logIds(exchange) + 
failureOrigin(exchange)
+                   + ": its route is being stopped or reloaded, so it is not 
continued."
+                   + " A consumer that rolls back, such as file, delivers it 
again",
+                level == LoggingLevel.ERROR ? LoggingLevel.WARN : level);
+        return true;
     }
 }
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/processor/errorhandler/RouteStopCutOffLogTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/processor/errorhandler/RouteStopCutOffLogTest.java
new file mode 100644
index 000000000000..e3cafa9ed426
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/processor/errorhandler/RouteStopCutOffLogTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.errorhandler;
+
+import java.util.List;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.log.ConsumingAppender;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * CAMEL-25484: an exchange that a route stop or a dev mode reload cuts off is 
logged as one WARN line, not as an
+ * exhausted failure with message history and stack trace.
+ */
+public class RouteStopCutOffLogTest extends ContextTestSupport {
+
+    private static final String LOGGER = DefaultErrorHandler.class.getName();
+
+    private final Queue<String> messages = new ConcurrentLinkedQueue<>();
+
+    @AfterEach
+    public void removeAppender() {
+        LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
+        ctx.getConfiguration().removeLogger(LOGGER);
+        ctx.updateLoggers();
+    }
+
+    @Test
+    public void theCutOffIsOneWarnLine() throws Exception {
+        ConsumingAppender.newAppender(LOGGER, "RouteStopCutOffLogTest", 
Level.DEBUG,
+                event -> messages.add(event.getLevel() + " " + 
event.getMessage().getFormattedMessage()
+                                      + (event.getThrown() != null ? " THROWN" 
: "")));
+        context.getShutdownStrategy().setTimeout(1);
+        context.getShutdownStrategy().setTimeUnit(TimeUnit.SECONDS);
+
+        context.getInflightRepository().setInflightBrowseEnabled(true);
+
+        template.sendBody("seda:start", List.of("A", "B"));
+        // the exchange waits for a consumer on direct:shipment, as after a 
save that sends to a route not written yet
+        await().atMost(5, TimeUnit.SECONDS).until(() -> 
context.getInflightRepository().browse().stream()
+                .anyMatch(e -> "shipment".equals(e.getNodeId())));
+        context.getRouteController().stopRoute("slow");
+
+        await().atMost(5, TimeUnit.SECONDS).until(() -> !messages.isEmpty());
+        assertEquals(1, messages.size(), messages.toString());
+        String message = messages.peek();
+        assertTrue(message.startsWith("WARN Exchange cut off (MessageId: "), 
message);
+        assertTrue(message.contains(": its route is being stopped or reloaded, 
so it is not continued."), message);
+        assertFalse(message.contains("Exhausted"), message);
+        assertFalse(message.contains("Message History"), message);
+        assertFalse(message.endsWith("THROWN"), message);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("seda:start").routeId("slow")
+                        .split(body())
+                            .log("Picked ${body}")
+                            .to("direct:shipment").id("shipment")
+                        .end()
+                        .to("mock:result");
+            }
+        };
+    }
+}
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
index 498efc029dec..0754870bfa4d 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc
@@ -1495,6 +1495,16 @@ A project whose routes are all in one file is covered 
too: the content that last
 broken save goes back to the version that was running, and the log says how 
many routes came from it. The file on
 disk is untouched; its next save is loaded as usual.
 
+=== camel-core - an exchange cut off by a route stop or reload is logged as 
one WARN line
+
+When a route is stopped or reloaded (for example a save in `camel run --dev`) 
while an exchange is in flight, and
+the graceful shutdown times out, the exchange is cut off. The error handler 
logged this as a failed delivery: an
+ERROR with "Exhausted after delivery attempt", the message history and the 
stack trace of the
+`RejectedExecutionException`. It is now one line at WARN, "Exchange cut off 
...: its route is being stopped or
+reloaded", as nothing in the route failed, and a consumer that rolls back, 
such as file, delivers the message again.
+A level lower than WARN configured for exhausted logging is kept. A forced 
stop of the CamelContext is logged as
+before. The exception set on the exchange is unchanged.
+
 === camel-core - RoutesLoader.updateRoutes runs one call at a time
 
 Concurrent `RoutesLoader.updateRoutes` calls on one CamelContext now run one 
at a time instead of failing with

Reply via email to