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

gnodet pushed a commit to branch camel-4.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.22.x by this push:
     new bd54ee955e39 [backport camel-4.22.x] CAMEL-26488: camel-mina - close 
the synchronous producer session when a request times out (#28887)
bd54ee955e39 is described below

commit bd54ee955e39a70dcbad081f0f411a9b8f2c0a48
Author: Guillaume Nodet <[email protected]>
AuthorDate: Mon Nov 2 17:34:09 2026 +0100

    [backport camel-4.22.x] CAMEL-26488: camel-mina - close the synchronous 
producer session when a request times out (#28887)
---
 .../java/org/apache/camel/component/mina/MinaProducer.java     | 10 ++++++----
 .../camel/component/mina/MinaDisconnectOnTimeOutTest.java      |  7 ++++---
 .../modules/ROOT/pages/camel-4x-upgrade-guide-4_22.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 bd192b368353..6f983d2a3591 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_22.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_22.adoc
index 0569602b5cdc..c4ec32ec16b0 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_22.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_22.adoc
@@ -1048,6 +1048,16 @@ skipped too. Before, such a link was consumed like any 
other file, wherever it p
 the first time and at DEBUG on later polls. Links resolving inside
 the starting directory work as before. Set `jailStartingDirectory=false` to 
keep following links to other directories.
 
+=== 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-mail - MimeMultipartDataFormat inbound header filtering
 
 When unmarshalling a MIME message with `headersInline=true`, the 
`mime-multipart` data format now applies a

Reply via email to