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 e45558b86144 CAMEL-26488: camel-mina - close the synchronous producer 
session when a request times out (#28865)
e45558b86144 is described below

commit e45558b861442c5ebcc07214c970d41c2b7b7c3c
Author: Andrea Cosentino <[email protected]>
AuthorDate: Mon Nov 2 15:40:59 2026 +0100

    CAMEL-26488: camel-mina - close the synchronous producer session when a 
request times out (#28865)
    
    Co-Authored-By: Claude Opus 4.8 <[email protected]>
    Signed-off-by: Andrea Cosentino <[email protected]>
---
 .../java/org/apache/camel/component/mina/MinaProducer.java     | 10 ++++++----
 .../camel/component/mina/MinaDisconnectOnTimeOutTest.java      |  7 ++++---
 .../modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc        | 10 ++++++++++
 3 files changed, 20 insertions(+), 7 deletions(-)

diff --git 
a/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java
 
b/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java
index ac00c7197fef..934b4e20db33 100644
--- 
a/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java
+++ 
b/components/camel-mina/src/main/java/org/apache/camel/component/mina/MinaProducer.java
@@ -198,10 +198,12 @@ public class MinaProducer extends DefaultProducer {
         if (session == null) {
             return;
         }
-        if (configuration.isDisconnectOnNoReply()) {
-            LOG.debug("Closing session when timed out at address: {}", 
address);
-            closeSessionIfNeededAndAwaitCloseInHandler(session);
-        }
+        // Always close the session of a producer that timed out waiting for a 
reply. A sync producer is
+        // non-singleton and is returned to the pool for reuse by later 
exchanges; if the session stayed open
+        // the late reply to this exchange could arrive on it and be handed to 
the next exchange that reuses
+        // this producer. disconnectOnNoReply only governs the consumer, so it 
is not consulted here.
+        LOG.debug("Closing session when timed out at address: {}", address);
+        closeSessionIfNeededAndAwaitCloseInHandler(session);
     }
 
     protected void maybeDisconnectOnDone(Exchange exchange) throws 
InterruptedException {
diff --git 
a/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaDisconnectOnTimeOutTest.java
 
b/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaDisconnectOnTimeOutTest.java
index 5c33a12af9f5..2f5a7bab7ace 100644
--- 
a/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaDisconnectOnTimeOutTest.java
+++ 
b/components/camel-mina/src/test/java/org/apache/camel/component/mina/MinaDisconnectOnTimeOutTest.java
@@ -47,12 +47,13 @@ public class MinaDisconnectOnTimeOutTest extends 
BaseMinaTest {
     }
 
     @Test
-    public void testSecondRequestReturnsWrongResult() {
+    public void 
testSecondRequestReturnsCorrectResultWithoutDisconnectOnNoReply() {
         int tooLong = 350;
         int fastEnough = 150;
         assertThrowable(ExchangeTimedOutException.class, () -> 
requestWithDelay(tooLong, false));
-        // YIKES! The response from the first query is returned for the second 
query. Better leave disconnectOnNoReply on true!
-        assertEquals(response(tooLong), requestWithDelay(fastEnough, false));
+        // The first request timed out, so the producer closed its session 
instead of reusing it. The second
+        // request opens a new session and receives its own reply rather than 
the late reply to the first request.
+        assertEquals(response(fastEnough), requestWithDelay(fastEnough, 
false));
     }
 
     @Override
diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index 3fc0178f4c68..1bc188419d61 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -2577,6 +2577,16 @@ MINA does not pass a failed handshake on as an error: 
the producer fails with a
 `org.apache.mina.filter.ssl.SslHandler`. A producer that starts timing out 
after the upgrade should be checked for a
 certificate that does not list the host.
 
+=== camel-mina - the producer closes its session when a request times out
+
+A synchronous `mina` producer (`sync=true`) now always closes its session when 
a request times out while waiting for a
+reply. Because a synchronous producer is pooled and reused for later 
exchanges, a session kept open after a timeout
+could receive the late reply to the timed-out exchange and hand it to the next 
exchange that reused the same producer.
+The producer now discards that session, so the next exchange opens a fresh one.
+
+The default behaviour is unchanged: `disconnectOnNoReply` defaults to `true`, 
which already closed the session on a
+timeout. Setting `disconnectOnNoReply=false` no longer keeps the producer 
session open after a timeout.
+
 === camel-ftp - the host name of the FTPS server is verified
 
 The `ftps` endpoint now checks, on the control connection, that the 
certificate of the server matches the host of the

Reply via email to