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 7b8b5d4cf698 CAMEL-25294: camel-consul - readTimeout and writeTimeout 
must set the read and write timeouts of the client (#27325)
7b8b5d4cf698 is described below

commit 7b8b5d4cf698c775cb4c38f3ec6aff9d9229171c
Author: allthingssecurity <[email protected]>
AuthorDate: Sun Oct 4 12:33:11 2026 +0530

    CAMEL-25294: camel-consul - readTimeout and writeTimeout must set the read 
and write timeouts of the client (#27325)
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../consul/ConsulClientConfiguration.java          |  4 +-
 .../ConsulClientConfigurationTimeoutTest.java      | 87 ++++++++++++++++++++++
 .../ROOT/pages/camel-4x-upgrade-guide-4_23.adoc    |  9 +++
 3 files changed, 98 insertions(+), 2 deletions(-)

diff --git 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulClientConfiguration.java
 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulClientConfiguration.java
index 714bd0eab2f2..f780f7f05550 100644
--- 
a/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulClientConfiguration.java
+++ 
b/components/camel-consul/src/main/java/org/apache/camel/component/consul/ConsulClientConfiguration.java
@@ -310,11 +310,11 @@ public abstract class ConsulClientConfiguration 
implements Cloneable {
         }
 
         if (ObjectHelper.isNotEmpty(readTimeout)) {
-            builder.withConnectTimeoutMillis(readTimeout.toMillis());
+            builder.withReadTimeoutMillis(readTimeout.toMillis());
         }
 
         if (ObjectHelper.isNotEmpty(writeTimeout)) {
-            builder.withConnectTimeoutMillis(writeTimeout.toMillis());
+            builder.withWriteTimeoutMillis(writeTimeout.toMillis());
         }
 
         return builder.build();
diff --git 
a/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulClientConfigurationTimeoutTest.java
 
b/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulClientConfigurationTimeoutTest.java
new file mode 100644
index 000000000000..ce9bc69025bf
--- /dev/null
+++ 
b/components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulClientConfigurationTimeoutTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.component.consul;
+
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.SocketTimeoutException;
+import java.time.Duration;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.function.Executable;
+import org.kiwiproject.consul.Consul;
+import org.kiwiproject.consul.ConsulException;
+
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
+
+/**
+ * The readTimeout and writeTimeout options must be applied to the Consul 
client. Without them the HTTP client waits 10
+ * seconds (its default), so a request to an agent that does not answer must 
fail well before that.
+ */
+class ConsulClientConfigurationTimeoutTest {
+
+    private static final Duration TIMEOUT = Duration.ofMillis(200);
+    private static final Duration MAX_WAIT = Duration.ofSeconds(5);
+
+    @Test
+    void readTimeout() throws Exception {
+        // the connection is accepted by the operating system (backlog) but 
nothing is ever answered
+        try (ServerSocket agent = new ServerSocket(0, 1, 
InetAddress.getLoopbackAddress())) {
+            ConsulConfiguration configuration = configuration(agent);
+            configuration.setReadTimeout(TIMEOUT);
+
+            assertTimesOut(configuration, consul -> 
consul.keyValueClient().getValueAsString("camel/key"));
+        }
+    }
+
+    @Test
+    void writeTimeout() throws Exception {
+        // nothing is ever read: writing a value larger than the socket 
buffers blocks
+        try (ServerSocket agent = new ServerSocket(0, 1, 
InetAddress.getLoopbackAddress())) {
+            ConsulConfiguration configuration = configuration(agent);
+            configuration.setWriteTimeout(TIMEOUT);
+
+            String value = "x".repeat(32 * 1024 * 1024);
+            assertTimesOut(configuration, consul -> 
consul.keyValueClient().putValue("camel/key", value));
+        }
+    }
+
+    private static ConsulConfiguration configuration(ServerSocket agent) {
+        ConsulConfiguration configuration = new ConsulConfiguration();
+        configuration.setUrl("http://localhost:"; + agent.getLocalPort());
+        configuration.setPingInstance(false);
+        return configuration;
+    }
+
+    private static void assertTimesOut(ConsulConfiguration configuration, 
ConsulCall call) throws Exception {
+        Consul consul = configuration.createConsulClient();
+        try {
+            Executable request = () -> call.execute(consul);
+            ConsulException e = assertTimeoutPreemptively(MAX_WAIT, () -> 
assertThrows(ConsulException.class, request));
+            assertInstanceOf(SocketTimeoutException.class, e.getCause());
+        } finally {
+            consul.destroy();
+        }
+    }
+
+    @FunctionalInterface
+    private interface ConsulCall {
+        void execute(Consul consul);
+    }
+}
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 4f6537cc7a39..17b251975ef4 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
@@ -546,6 +546,15 @@ sent to the partition with the same id in the target Event 
Hub. To keep doing so
 Event Hubs that have the same partitions, remove the 
`CamelAzureEventHubsReceivedPartitionId` exchange property before
 the producer.
 
+=== camel-consul - readTimeout and writeTimeout
+
+The `readTimeout` and `writeTimeout` options (also on the Consul cluster 
service) set the connect timeout of the
+Consul client instead of its read and write timeouts. So the client always 
used the default read and write timeouts
+of its HTTP client (10 seconds), and the connect timeout was `writeTimeout` 
when it was set, otherwise `readTimeout`,
+otherwise `connectTimeout`. Each option now sets its own timeout: a request 
whose answer takes longer than a
+configured `readTimeout` now fails, and only `connectTimeout` sets the connect 
timeout. Blocking queries
+(`blockSeconds`) are not affected: the client computes the read timeout of a 
blocking query from its wait time.
+
 === camel-couchbase
 
 The `connectTimeout` option is now applied. It previously sat inside a 
condition that tested `queryTimeout`, so

Reply via email to