This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch camel-4.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.18.x by this push:
new 334989e6e055 [backport camel-4.18.x] CAMEL-26488: camel-mina - close
the synchronous producer session when a request times out (#28888)
334989e6e055 is described below
commit 334989e6e055f84a0b0996922b76b758f8e56fbd
Author: Guillaume Nodet <[email protected]>
AuthorDate: Mon Nov 2 16:56:43 2026 +0100
[backport camel-4.18.x] CAMEL-26488: camel-mina - close the synchronous
producer session when a request times out (#28888)
---
.../java/org/apache/camel/component/mina/MinaProducer.java | 10 ++++++----
.../camel/component/mina/MinaDisconnectOnTimeOutTest.java | 7 ++++---
.../modules/ROOT/pages/camel-4x-upgrade-guide-4_18.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_18.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_18.adoc
index a42fe35b6b4e..8e6b3fa199e5 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_18.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_18.adoc
@@ -1980,3 +1980,13 @@ now refuses to send a request path, query or header
value that contains a contro
framing, are still allowed. Routes that put a percent-encoded control
character (such as `%0D%0A`) into the
`CamelHttpPath` or `CamelHttpQuery` header, which the producer decodes before
building the request, are the ones most
likely to be affected.
+
+=== 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.