Re: [PR] CAMEL-23459: Add TTL cleanup for pending async tasks to prevent memory leak [camel]
oscerd merged PR #23125: URL: https://github.com/apache/camel/pull/23125 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] CAMEL-23459: Add TTL cleanup for pending async tasks to prevent memory leak [camel]
github-actions[bot] commented on PR #23125: URL: https://github.com/apache/camel/pull/23125#issuecomment-4428440273 :test_tube: **CI tested the following changed modules:** - `catalog/camel-catalog` - `components/camel-ai/camel-docling` - `dsl/camel-componentdsl` - `dsl/camel-endpointdsl` :warning: **Some tests are disabled on GitHub Actions** (`@DisabledIfSystemProperty(named = "ci.env.name")`) and require manual verification: - `components/camel-ai/camel-docling`: 6 test(s) disabled on GitHub Actions All tested modules (11 modules) - Camel :: AI :: Docling - Camel :: Catalog :: Camel Catalog - Camel :: Component DSL - Camel :: Endpoint DSL - Camel :: JBang :: MCP - Camel :: JBang :: Plugin :: Route Parser - Camel :: JBang :: Plugin :: TUI - Camel :: JBang :: Plugin :: Validate - Camel :: Launcher :: Container - Camel :: YAML DSL :: Validator - Camel :: YAML DSL :: Validator Maven Plugin --- :gear: [View full build and test results](https://github.com/apache/camel/actions/runs/25720388591) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] CAMEL-23459: Add TTL cleanup for pending async tasks to prevent memory leak [camel]
oscerd commented on PR #23125: URL: https://github.com/apache/camel/pull/23125#issuecomment-4428322835 Pushed 7c1479fa90e addressing all of @gnodet's and @davsclaus's review feedback: **Blocking items** - **Stale generated files** (@davsclaus / @gnodet "Blocking 1"): regenerated and committed `catalog/.../docling.json`, `DoclingComponentBuilderFactory.java`, and `DoclingEndpointBuilderFactory.java`. Verified that a clean `mvn clean install -DskipTests` from the repo root now produces no further uncommitted regen artifacts. - **`Thread.sleep` in tests** (@gnodet "Blocking 2"): replaced with the suggested Awaitility `during/atMost` pattern. **Non-blocking suggestions (both applied)** - **Test comment vs actual behavior** (@gnodet #3): this turned out to be more than a comment error — with the 60s minimum, the cleanup-interval was actually 60s for the 2s test TTL, so the existing `atMost(5, SECONDS)` could never fire. Lowered the cleanup-interval floor from 60s → 1s (cleanup is cheap when the map is empty, so the lower minimum is safe and makes short TTLs actually meaningful), corrected the test comment, bumped `atMost` to 8s for headroom, and added `isUseAdviceWith() = true` so the test-configured TTL is in effect by the time `doStart` runs. - **Logging level** (@gnodet #4): lowered `doStart`/`doStop`/cleanup-summary lines from `LOG.info` to `LOG.debug`. **Drive-by** While running the test suite I also found that the pre-existing `DoclingAsyncConversionTest` wasn't updated when the PR changed the map's value type to `AsyncTaskEntry` — it was still inserting raw `CompletableFuture` and producing `ClassCastException` on 3 tests. Updated the test to wrap in `AsyncTaskEntry`. **Verification** - camel-docling: 49 tests, 0 failures, 0 errors (was 3 ClassCastException errors on `DoclingAsyncConversionTest` + flaky `DoclingAsyncTaskTtlTest`). - Full reactor `mvn clean install -DskipTests` from root: SUCCESS in 8:42. - `git status` clean after the full reactor build — no further regen artifacts. cc @Croway @davsclaus @gnodet for re-review when convenient. _Claude Code on behalf of Andrea Cosentino_ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] CAMEL-23459: Add TTL cleanup for pending async tasks to prevent memory leak [camel]
oscerd commented on code in PR #23125:
URL: https://github.com/apache/camel/pull/23125#discussion_r3224558827
##
components/camel-ai/camel-docling/src/test/java/org/apache/camel/component/docling/DoclingAsyncTaskTtlTest.java:
##
@@ -0,0 +1,131 @@
+/*
+ * 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.docling;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * Test TTL-based cleanup of pending async conversion tasks.
+ */
+public class DoclingAsyncTaskTtlTest extends CamelTestSupport {
+
+@Test
+public void testAsyncTaskTtlEviction() throws Exception {
+// Get the component to access pending tasks map
+DoclingComponent component = context.getComponent("docling",
DoclingComponent.class);
+assertNotNull(component);
+
+// Configure with a short TTL (2 seconds) for testing
+component.getConfiguration().setAsyncTaskTtl(2000);
+component.getConfiguration().setUseDoclingServe(true);
+
component.getConfiguration().setDoclingServeUrl("http://localhost:5001";);
+
+// Start the component to trigger cleanup scheduler
+context.start();
+
+// Simulate adding a task entry directly (since we don't have a real
docling-serve)
+String taskId = "test-task-1";
+AsyncTaskEntry entry = new AsyncTaskEntry(taskId, new
java.util.concurrent.CompletableFuture<>());
+component.getPendingAsyncTasks().put(taskId, entry);
+
+// Verify task is present
+assertEquals(1, component.getPendingAsyncTasks().size());
+
+// Wait for TTL to expire and cleanup to run
+// Cleanup runs every 10% of TTL (minimum 1 minute), but for 2s TTL
that's 200ms
+// Add buffer for cleanup execution
+await().atMost(5, TimeUnit.SECONDS)
+.untilAsserted(() -> assertEquals(0,
component.getPendingAsyncTasks().size()));
+}
+
+@Test
+public void testAsyncTaskNotEvictedBeforeTtl() throws Exception {
+// Get the component
+DoclingComponent component = context.getComponent("docling",
DoclingComponent.class);
+assertNotNull(component);
+
+// Configure with a longer TTL (10 seconds)
+component.getConfiguration().setAsyncTaskTtl(1);
+component.getConfiguration().setUseDoclingServe(true);
+
component.getConfiguration().setDoclingServeUrl("http://localhost:5001";);
+
+context.start();
+
+// Add a task entry
+String taskId = "test-task-2";
+AsyncTaskEntry entry = new AsyncTaskEntry(taskId, new
java.util.concurrent.CompletableFuture<>());
+component.getPendingAsyncTasks().put(taskId, entry);
+
+// Verify task is present
+assertEquals(1, component.getPendingAsyncTasks().size());
+
+// Wait a short time (less than TTL)
+Thread.sleep(1000);
+
Review Comment:
Fixed in 7c1479fa90e — replaced `Thread.sleep(1000)` with the suggested
Awaitility `during/atMost` pattern.
_Claude Code on behalf of Andrea Cosentino_
##
components/camel-ai/camel-docling/src/test/java/org/apache/camel/component/docling/DoclingAsyncTaskTtlTest.java:
##
@@ -0,0 +1,131 @@
+/*
+ * 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 expr
Re: [PR] CAMEL-23459: Add TTL cleanup for pending async tasks to prevent memory leak [camel]
oscerd commented on code in PR #23125:
URL: https://github.com/apache/camel/pull/23125#discussion_r3224560346
##
components/camel-ai/camel-docling/src/main/java/org/apache/camel/component/docling/DoclingComponent.java:
##
@@ -51,6 +58,26 @@ public DoclingComponent(CamelContext context) {
this.configuration = new DoclingConfiguration();
}
+@Override
+protected void doStart() throws Exception {
+super.doStart();
+
+// Start scheduled cleanup task for expired async tasks
+long ttl = configuration.getAsyncTaskTtl();
+long cleanupInterval = Math.max(ttl / 10, 6); // Run cleanup every
10% of TTL, minimum 1 minute
+
+cleanupExecutor = getCamelContext().getExecutorServiceManager()
+.newScheduledThreadPool(this, "DoclingAsyncTaskCleanup", 1);
+
+cleanupExecutor.scheduleWithFixedDelay(
+this::cleanupExpiredTasks,
+cleanupInterval,
+cleanupInterval,
+TimeUnit.MILLISECONDS);
+
+LOG.info("Started async task cleanup with TTL={}ms, cleanup
interval={}ms", ttl, cleanupInterval);
Review Comment:
Fixed in 7c1479fa90e — lowered all three call sites (`doStart`,
`cleanupExpiredTasks` summary line, `doStop`) from `LOG.info` to `LOG.debug`.
The per-task eviction log was already at DEBUG.
_Claude Code on behalf of Andrea Cosentino_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Re: [PR] CAMEL-23459: Add TTL cleanup for pending async tasks to prevent memory leak [camel]
gnodet commented on code in PR #23125:
URL: https://github.com/apache/camel/pull/23125#discussion_r3224042400
##
components/camel-ai/camel-docling/src/test/java/org/apache/camel/component/docling/DoclingAsyncTaskTtlTest.java:
##
@@ -0,0 +1,131 @@
+/*
+ * 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.docling;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * Test TTL-based cleanup of pending async conversion tasks.
+ */
+public class DoclingAsyncTaskTtlTest extends CamelTestSupport {
+
+@Test
+public void testAsyncTaskTtlEviction() throws Exception {
+// Get the component to access pending tasks map
+DoclingComponent component = context.getComponent("docling",
DoclingComponent.class);
+assertNotNull(component);
+
+// Configure with a short TTL (2 seconds) for testing
+component.getConfiguration().setAsyncTaskTtl(2000);
+component.getConfiguration().setUseDoclingServe(true);
+
component.getConfiguration().setDoclingServeUrl("http://localhost:5001";);
+
+// Start the component to trigger cleanup scheduler
+context.start();
+
+// Simulate adding a task entry directly (since we don't have a real
docling-serve)
+String taskId = "test-task-1";
+AsyncTaskEntry entry = new AsyncTaskEntry(taskId, new
java.util.concurrent.CompletableFuture<>());
+component.getPendingAsyncTasks().put(taskId, entry);
+
+// Verify task is present
+assertEquals(1, component.getPendingAsyncTasks().size());
+
+// Wait for TTL to expire and cleanup to run
+// Cleanup runs every 10% of TTL (minimum 1 minute), but for 2s TTL
that's 200ms
+// Add buffer for cleanup execution
Review Comment:
Nit: this comment says "for 2s TTL that's 200ms" but the production code
does `Math.max(ttl / 10, 6)`, which clamps to a **1-minute minimum**, not
200ms.
If the cleanup interval is really 60s, the `await().atMost(5, SECONDS)` on
line 60 will time out before the first cleanup fires. Worth verifying this test
passes reliably — the comment at minimum should be corrected.
_Claude Code on behalf of Guillaume Nodet_
##
components/camel-ai/camel-docling/src/test/java/org/apache/camel/component/docling/DoclingAsyncTaskTtlTest.java:
##
@@ -0,0 +1,131 @@
+/*
+ * 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.docling;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+/**
+ * Test TTL-based cleanup of pending async conversion tasks.
+ */
+public class DoclingAsyncTaskTtlTest extends CamelTestSupport {
+
+@Test
+public void testAsyncTaskTtlEviction() throws Exception {
+// Get the component to access pending tasks map
+DoclingComponent component
Re: [PR] CAMEL-23459: Add TTL cleanup for pending async tasks to prevent memory leak [camel]
davsclaus commented on PR #23125: URL: https://github.com/apache/camel/pull/23125#issuecomment-4423304482 Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git restore ..." to discard changes in working directory) modified: catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/docling.json modified: dsl/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/DoclingComponentBuilderFactory.java modified: dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/DoclingEndpointBuilderFactory.java -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] CAMEL-23459: Add TTL cleanup for pending async tasks to prevent memory leak [camel]
github-actions[bot] commented on PR #23125: URL: https://github.com/apache/camel/pull/23125#issuecomment-4421845088 :star2: Thank you for your contribution to the Apache Camel project! :star2: :robot: CI automation will test this PR automatically. :camel: Apache Camel Committers, please review the following items: * First-time contributors **require MANUAL approval** for the GitHub Actions to run * You can use the command `/component-test (camel-)component-name1 (camel-)component-name2..` to request a test from the test bot although they are normally detected and executed by CI. * You can label PRs using `skip-tests` and `test-dependents` to fine-tune the checks executed by this PR. * Build and test logs are available in the summary page. **Only** [Apache Camel committers](https://camel.apache.org/community/team/#committers) have access to the summary. :warning: Be careful when sharing logs. Review their contents before sharing them publicly. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
