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 8102a74e807b CAMEL-27490: camel-aws-secrets-manager - the CloudTrail 
and SQS calls of the secret refresh task time out after 10 seconds (#30826)
8102a74e807b is described below

commit 8102a74e807b54712428dca28cb191857662a060
Author: allthingssecurity <[email protected]>
AuthorDate: Thu Nov 26 13:31:12 2026 +0530

    CAMEL-27490: camel-aws-secrets-manager - the CloudTrail and SQS calls of 
the secret refresh task time out after 10 seconds (#30826)
    
    All the periodic tasks of a CamelContext run one after the other on the
    single thread of its TimerListenerManager: the secret refresh tasks of
    every vault, and others such as the Service Bus lock renewer. The
    CloudTrail refresh task built its CloudTrailClient and SqsClient without
    an API call timeout, so a call that got no answer held that thread for as
    long as the HTTP client waited, and no other periodic task ran. With SQS
    notification, a receive wait time (long polling) set on the queue also
    made each check wait on that thread.
    
    Both clients now get an apiCallTimeout of 10 seconds, retries included:
    a call that times out is logged and tried again at the next check, as any
    other failed call. The SQS receive sets a wait time of 0 seconds, as the
    check runs again after the refresh period anyway. The component page
    (and its catalog copy) and the 4.24 upgrade guide say so. Other blocking
    work on the shared thread, such as the context reload itself, is not
    changed.
    
    New CloudTrailReloadTriggerTaskCallTimeoutTest, with the real SDK
    clients against a local HTTP server that does not answer: a check in
    CloudTrail and in SQS mode ends after the call timeout, the receive does
    not wait, and another periodic task keeps running while CloudTrail does
    not answer.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../docs/aws-secrets-manager-component.adoc        |   4 +
 .../main/docs/aws-secrets-manager-component.adoc   |   4 +
 .../vault/CloudTrailReloadTriggerTask.java         |  22 ++-
 ...CloudTrailReloadTriggerTaskCallTimeoutTest.java | 155 +++++++++++++++++++++
 .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc    |   8 ++
 5 files changed, 190 insertions(+), 3 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/aws-secrets-manager-component.adoc
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/aws-secrets-manager-component.adoc
index 6ee548164c42..c34ba0168a5c 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/aws-secrets-manager-component.adoc
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/aws-secrets-manager-component.adoc
@@ -515,6 +515,10 @@ where queue_url is the AWS SQS Queue URL of the just 
created Queue.
 
 Whenever an event of PutSecretValue for the Secret named 'Secret' will happen, 
a message will be enqueued in the AWS SQS Queue and consumed on the Camel side 
and a context reload will be triggered.
 
+The task polls the queue without waiting for messages (`WaitTimeSeconds` is 0, 
whatever the receive wait time set on the queue): it checks again after the 
refresh period.
+
+NOTE: The refresh task runs on the thread that runs all the periodic tasks of 
the Camel context. So that an AWS service that does not answer cannot hold that 
thread, each call of the task to CloudTrail or SQS times out after 10 seconds 
(retries included), and the task tries again on its next run.
+
 
 === Secrets Manager Producer operations
 
diff --git 
a/components/camel-aws/camel-aws-secrets-manager/src/main/docs/aws-secrets-manager-component.adoc
 
b/components/camel-aws/camel-aws-secrets-manager/src/main/docs/aws-secrets-manager-component.adoc
index 6ee548164c42..c34ba0168a5c 100644
--- 
a/components/camel-aws/camel-aws-secrets-manager/src/main/docs/aws-secrets-manager-component.adoc
+++ 
b/components/camel-aws/camel-aws-secrets-manager/src/main/docs/aws-secrets-manager-component.adoc
@@ -515,6 +515,10 @@ where queue_url is the AWS SQS Queue URL of the just 
created Queue.
 
 Whenever an event of PutSecretValue for the Secret named 'Secret' will happen, 
a message will be enqueued in the AWS SQS Queue and consumed on the Camel side 
and a context reload will be triggered.
 
+The task polls the queue without waiting for messages (`WaitTimeSeconds` is 0, 
whatever the receive wait time set on the queue): it checks again after the 
refresh period.
+
+NOTE: The refresh task runs on the thread that runs all the periodic tasks of 
the Camel context. So that an AWS service that does not answer cannot hold that 
thread, each call of the task to CloudTrail or SQS times out after 10 seconds 
(retries included), and the task tries again on its next run.
+
 
 === Secrets Manager Producer operations
 
diff --git 
a/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/vault/CloudTrailReloadTriggerTask.java
 
b/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/vault/CloudTrailReloadTriggerTask.java
index 3274cfb193ab..8d71fae2ba3a 100644
--- 
a/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/vault/CloudTrailReloadTriggerTask.java
+++ 
b/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/vault/CloudTrailReloadTriggerTask.java
@@ -44,6 +44,7 @@ import org.slf4j.LoggerFactory;
 import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
 import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
 import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
+import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
 import software.amazon.awssdk.regions.Region;
 import software.amazon.awssdk.services.cloudtrail.CloudTrailClient;
 import software.amazon.awssdk.services.cloudtrail.CloudTrailClientBuilder;
@@ -104,6 +105,9 @@ public class CloudTrailReloadTriggerTask extends 
ServiceSupport implements Camel
 
     // the largest page that LookupEvents accepts
     private static final int LOOKUP_MAX_RESULTS = 50;
+    // the longest one call to CloudTrail or SQS may take, retries included: 
the task runs on the thread that runs every
+    // periodic task of the CamelContext, so a call that hangs must not hold 
that thread for longer than this
+    static final Duration API_CALL_TIMEOUT = Duration.ofSeconds(10);
     // the events that change the value of a secret, looked up one by one
     private static final List<String> UPDATE_EVENT_NAMES
             = List.of(SECRETSMANAGER_UPDATE_EVENT, 
SECRETSMANAGER_UPDATE_SECRET_EVENT);
@@ -116,6 +120,7 @@ public class CloudTrailReloadTriggerTask extends 
ServiceSupport implements Camel
     private String secrets;
     private CloudTrailClient cloudTrailClient;
     private SqsClient sqsClient;
+    private Duration apiCallTimeout = API_CALL_TIMEOUT;
     private SecretsManagerPropertiesFunction propertiesFunction;
     private volatile Instant lastTime;
     // the time the task started to look for updates: no check looks up events 
before it
@@ -174,6 +179,13 @@ public class CloudTrailReloadTriggerTask extends 
ServiceSupport implements Camel
         return lastReloadTime;
     }
 
+    /**
+     * The longest one call to CloudTrail or SQS may take, retries included 
(for testing).
+     */
+    void setApiCallTimeout(Duration apiCallTimeout) {
+        this.apiCallTimeout = apiCallTimeout;
+    }
+
     @Override
     protected void doStart() throws Exception {
         super.doStart();
@@ -219,8 +231,10 @@ public class CloudTrailReloadTriggerTask extends 
ServiceSupport implements Camel
                 queueUrl = awsVaultConfiguration.getSqsQueueUrl();
             }
         }
+        ClientOverrideConfiguration overrideConfiguration
+                = 
ClientOverrideConfiguration.builder().apiCallTimeout(apiCallTimeout).build();
         if (!useSqsNotification) {
-            CloudTrailClientBuilder clientBuilder = CloudTrailClient.builder();
+            CloudTrailClientBuilder clientBuilder = 
CloudTrailClient.builder().overrideConfiguration(overrideConfiguration);
             if (ObjectHelper.isNotEmpty(accessKey) && 
ObjectHelper.isNotEmpty(secretKey) && ObjectHelper.isNotEmpty(region)) {
 
                 AwsBasicCredentials cred = 
AwsBasicCredentials.create(accessKey, secretKey);
@@ -243,7 +257,7 @@ public class CloudTrailReloadTriggerTask extends 
ServiceSupport implements Camel
                 startedAt = lastTime;
             }
         } else {
-            SqsClientBuilder clientBuilder = SqsClient.builder();
+            SqsClientBuilder clientBuilder = 
SqsClient.builder().overrideConfiguration(overrideConfiguration);
             if (ObjectHelper.isNotEmpty(accessKey) && 
ObjectHelper.isNotEmpty(secretKey) && ObjectHelper.isNotEmpty(region)) {
                 AwsBasicCredentials cred = 
AwsBasicCredentials.create(accessKey, secretKey);
                 clientBuilder = 
clientBuilder.credentialsProvider(StaticCredentialsProvider.create(cred));
@@ -392,7 +406,9 @@ public class CloudTrailReloadTriggerTask extends 
ServiceSupport implements Camel
             }
         } else {
             try {
-                ReceiveMessageRequest.Builder request = 
ReceiveMessageRequest.builder().queueUrl(queueUrl);
+                // no long polling, whatever the receive wait time of the 
queue: the check runs again after the refresh
+                // period, and it must not wait on the thread of the periodic 
tasks (nor for longer than the call timeout)
+                ReceiveMessageRequest.Builder request = 
ReceiveMessageRequest.builder().queueUrl(queueUrl).waitTimeSeconds(0);
 
                 LOG.trace("Receiving messages with request [{}]...", request);
 
diff --git 
a/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/vault/CloudTrailReloadTriggerTaskCallTimeoutTest.java
 
b/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/vault/CloudTrailReloadTriggerTaskCallTimeoutTest.java
new file mode 100644
index 000000000000..116152c338b0
--- /dev/null
+++ 
b/components/camel-aws/camel-aws-secrets-manager/src/test/java/org/apache/camel/component/aws/secretsmanager/vault/CloudTrailReloadTriggerTaskCallTimeoutTest.java
@@ -0,0 +1,155 @@
+/*
+ * 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.aws.secretsmanager.vault;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
+import java.time.Duration;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpServer;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.spi.PeriodTaskScheduler;
+import org.apache.camel.support.PluginHelper;
+import org.apache.camel.vault.AwsVaultConfiguration;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * A call to CloudTrail or SQS that hangs ends after the API call timeout, so 
the refresh task does not hold the thread
+ * that runs every periodic task of the CamelContext. Runs against a local 
HTTP server that never answers.
+ */
+class CloudTrailReloadTriggerTaskCallTimeoutTest {
+
+    private static final Duration TIMEOUT = Duration.ofMillis(500);
+
+    // released at the end of the test: until then the server does not answer
+    private final CountDownLatch release = new CountDownLatch(1);
+    private final CountDownLatch requestArrived = new CountDownLatch(1);
+    private final List<String> requestBodies = new CopyOnWriteArrayList<>();
+    private final ExecutorService serverThreads = 
Executors.newCachedThreadPool();
+    private final ExecutorService caller = Executors.newSingleThreadExecutor();
+    private HttpServer server;
+    private DefaultCamelContext context;
+    private CloudTrailReloadTriggerTask task;
+
+    @BeforeEach
+    void setUp() throws IOException {
+        server = HttpServer.create(new InetSocketAddress("localhost", 0), 0);
+        server.createContext("/", this::hang);
+        server.setExecutor(serverThreads);
+        server.start();
+
+        context = new DefaultCamelContext();
+        AwsVaultConfiguration aws = new AwsVaultConfiguration();
+        aws.setAccessKey("ak");
+        aws.setSecretKey("sk");
+        aws.setRegion("us-east-1");
+        aws.setSecrets("tracked-secret");
+        aws.setOverrideEndpoint(true);
+        aws.setUriEndpointOverride("http://localhost:"; + 
server.getAddress().getPort());
+        context.getVaultConfiguration().setAwsVaultConfiguration(aws);
+    }
+
+    @AfterEach
+    void tearDown() {
+        release.countDown();
+        if (task != null) {
+            task.stop();
+            task.shutdown();
+        }
+        context.stop();
+        caller.shutdownNow();
+        server.stop(0);
+        serverThreads.shutdownNow();
+    }
+
+    private void hang(HttpExchange http) throws IOException {
+        try (InputStream in = http.getRequestBody()) {
+            requestBodies.add(new String(in.readAllBytes(), 
StandardCharsets.UTF_8));
+        }
+        requestArrived.countDown();
+        try {
+            release.await(60, TimeUnit.SECONDS);
+        } catch (InterruptedException e) {
+            Thread.currentThread().interrupt();
+        }
+        http.sendResponseHeaders(500, -1);
+        http.close();
+    }
+
+    private void startTask() {
+        task = new CloudTrailReloadTriggerTask();
+        task.setCamelContext(context);
+        task.setApiCallTimeout(TIMEOUT);
+        task.start();
+    }
+
+    private void assertRunEndsWithinTheTimeout() throws Exception {
+        Future<?> run = caller.submit(task::run);
+        assertTrue(requestArrived.await(10, TimeUnit.SECONDS), "the task calls 
AWS");
+        // the call timeout, plus some slack for a slow machine; the store 
itself would hold the call for 60 seconds
+        run.get(5, TimeUnit.SECONDS);
+    }
+
+    @Test
+    void lookupThatHangsEndsAfterTheCallTimeout() throws Exception {
+        startTask();
+        assertRunEndsWithinTheTimeout();
+    }
+
+    @Test
+    void receiveThatHangsEndsAfterTheCallTimeout() throws Exception {
+        context.getVaultConfiguration().aws().setUseSqsNotification(true);
+        
context.getVaultConfiguration().aws().setSqsQueueUrl("http://localhost:"; + 
server.getAddress().getPort() + "/queue");
+        startTask();
+        assertRunEndsWithinTheTimeout();
+        // JSON or query protocol
+        
assertTrue(requestBodies.get(0).matches("(?s).*WaitTimeSeconds\\W+0\\b.*"),
+                "the receive must not wait for messages, but was: " + 
requestBodies.get(0));
+    }
+
+    @Test
+    void lookupThatHangsDoesNotStallTheOtherPeriodicTasks() throws Exception {
+        context.start();
+        startTask();
+        // stands for any other periodic task of the CamelContext, run by the 
same thread as the refresh task
+        AtomicReference<CountDownLatch> probeRuns = new AtomicReference<>(new 
CountDownLatch(0));
+        PeriodTaskScheduler scheduler = 
PluginHelper.getPeriodTaskScheduler(context);
+        scheduler.schedulePeriodTask(() -> probeRuns.get().countDown(), 1000);
+        scheduler.schedulePeriodTask(task, 1000);
+
+        assertTrue(requestArrived.await(20, TimeUnit.SECONDS), "the task calls 
CloudTrail");
+        CountDownLatch afterHang = new CountDownLatch(2);
+        probeRuns.set(afterHang);
+        assertTrue(afterHang.await(10, TimeUnit.SECONDS),
+                "the other periodic task must keep running while CloudTrail 
does not answer");
+    }
+}
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 aef2f9421cc8..5dc182e93920 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
@@ -7135,6 +7135,14 @@ Each check looks up these events from 10 minutes before 
the newest event seen (b
 skips the events seen by an earlier check: CloudTrail can make an event 
visible after a newer one, and such an update was
 never read. The number of requests is as above, counted over that range.
 
+=== camel-aws-secrets-manager - the calls of the refresh task time out
+
+With `camel.vault.aws.refreshEnabled=true`, each call of the refresh task to 
CloudTrail or SQS now times out after 10
+seconds, retries included, and the task tries again at its next check. Before, 
a call that did not get an answer held
+the thread that runs all the periodic tasks of the Camel context for as long 
as the HTTP client waited. With SQS
+notification, the task no longer waits for messages: it receives with a wait 
time of 0 seconds, whatever receive wait
+time (long polling) is set on the queue.
+
 === camel-aws2-s3 - a timestamp window uploaded more than once is stored in 
more than one object
 
 With `streamingUploadMode=true` and `timestampGroupingEnabled=true`, the 
upload of a time window is completed when it

Reply via email to