You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2026/02/02 12:31:49 UTC
(camel) 01/01: Fix Task API usage: use withInitialDelay() instead of withInterval()
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch CAMEL-22898-fix-pubsub-memory-leak
in repository https://gitbox.apache.org/repos/asf/camel.git
commit f40fe763073ecad75378de8fcdad962da89d5863
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Mon Feb 2 13:31:33 2026 +0100
Fix Task API usage: use withInitialDelay() instead of withInterval()
The ForegroundTask only sleeps between iterations, not before the first iteration.
For a one-time delay with maxIterations(1), we must use withInitialDelay() to ensure
the delay happens before the first iteration.
This fixes the backoff delay in both GooglePubsubConsumer and GooglePubsubLiteConsumer.
---
.../camel/component/google/pubsublite/GooglePubsubLiteConsumer.java | 4 +++-
.../apache/camel/component/google/pubsub/GooglePubsubConsumer.java | 4 +++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/components/camel-google/camel-google-pubsub-lite/src/main/java/org/apache/camel/component/google/pubsublite/GooglePubsubLiteConsumer.java b/components/camel-google/camel-google-pubsub-lite/src/main/java/org/apache/camel/component/google/pubsublite/GooglePubsubLiteConsumer.java
index 47049f0db09b..40ca62c54ebb 100644
--- a/components/camel-google/camel-google-pubsub-lite/src/main/java/org/apache/camel/component/google/pubsublite/GooglePubsubLiteConsumer.java
+++ b/components/camel-google/camel-google-pubsub-lite/src/main/java/org/apache/camel/component/google/pubsublite/GooglePubsubLiteConsumer.java
@@ -150,10 +150,12 @@ public class GooglePubsubLiteConsumer extends DefaultConsumer {
}
// Add backoff delay for recoverable errors to prevent tight loop
+ // We use initialDelay for the actual delay, and maxIterations(1) to run once
Tasks.foregroundTask()
.withBudget(Budgets.iterationBudget()
.withMaxIterations(1)
- .withInterval(Duration.ofSeconds(5))
+ .withInitialDelay(Duration.ofSeconds(5))
+ .withInterval(Duration.ZERO)
.build())
.withName("PubSubLiteRetryDelay")
.build()
diff --git a/components/camel-google/camel-google-pubsub/src/main/java/org/apache/camel/component/google/pubsub/GooglePubsubConsumer.java b/components/camel-google/camel-google-pubsub/src/main/java/org/apache/camel/component/google/pubsub/GooglePubsubConsumer.java
index 620cb9f2c60c..87eec29c3669 100644
--- a/components/camel-google/camel-google-pubsub/src/main/java/org/apache/camel/component/google/pubsub/GooglePubsubConsumer.java
+++ b/components/camel-google/camel-google-pubsub/src/main/java/org/apache/camel/component/google/pubsub/GooglePubsubConsumer.java
@@ -204,10 +204,12 @@ public class GooglePubsubConsumer extends DefaultConsumer {
}
// Add backoff delay for recoverable errors to prevent tight loop
+ // We use initialDelay for the actual delay, and maxIterations(1) to run once
Tasks.foregroundTask()
.withBudget(Budgets.iterationBudget()
.withMaxIterations(1)
- .withInterval(Duration.ofSeconds(5))
+ .withInitialDelay(Duration.ofSeconds(5))
+ .withInterval(Duration.ZERO)
.build())
.withName("PubSubRetryDelay")
.build()