msnijder30 opened a new pull request, #24283:
URL: https://github.com/apache/camel/pull/24283

   # Description
   
   I found out about this issue with pollEnrich because we had a memory issue 
with the SFTP component because we did not set the cache size so it defaulted 
to 1000. So I read the documentation and set it to cachesize to -1, but the 
memory still kept going up.
   
   Our code was using dynamic endpoints that triggered this.
   
   pollEnrich().cacheSize(-1) is documented to disable the consumer cache 
entirely - polling consumers should be created fresh for each call and 
discarded immediately after use. However, this does not appear to work.
   
   Root cause: PollEnricher.doBuild() unconditionally creates a 
DefaultConsumerCache regardless of cacheSize. DefaultConsumerCache then 
normalizes any cacheSize <= 0 to the CamelContext maximum cache pool size 
(default 1000):
   
   ```java
   // DefaultConsumerCache line 55
   this.maxCacheSize = cacheSize <= 0 ? 
CamelContextHelper.getMaximumCachePoolSize(camelContext) : cacheSize;
   ```
   
   So instead of discarding consumers, up to 1000 polling consumers are 
retained in a cache. 
   
   For resource-backed components (e.g., SFTP), each retained consumer 
represents an open connection that is never cleaned up until the route stops.
   
   ## Reproducer
   You can find my reproducer here: 
https://github.com/msnijder30/reproduce-camel-pollenrich-cache-issue
   Also attached as zip to the JIRA ticket.
   
   ## The fix
   This mirrors how DefaultProducerCache (via EmptyProducerCache) already works 
on the producer side for cacheSize(-1).
   
   Didn't create a DefaultConsumerCache class because it's only used in this 
class, unlike DefaultProducerCache which is used in multiple places.
   
   Let me know what you think 👍 it was interesting to run into this bug
   
   # Target
   
   - [X] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [X] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue]
   - https://issues.apache.org/jira/browse/CAMEL-23840
   
   <!--
   # *Note*: trivial changes like, typos, minor documentation fixes and other 
small items do not require a JIRA issue. In this case your pull request should 
address just this issue, without pulling in other changes.
   -->
   
   # Apache Camel coding standards and style
   
   - [X] I checked that each commit in the pull request has a meaningful 
subject line and body.
   
   <!--
   If you're unsure, you can format the pull request title like `[CAMEL-XXX] 
Fixes bug in camel-file component`, where you replace `CAMEL-XXX` with the 
appropriate JIRA issue.
   -->
   
   - [X] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
   
   <!--
   You can run the aforementioned command in your module so that the build 
auto-formats your code. This will also be verified as part of the checks and 
your PR may be rejected if if there are uncommited changes after running `mvn 
clean install -DskipTests`.
   
   You can learn more about the contribution guidelines at 
https://github.com/apache/camel/blob/main/CONTRIBUTING.md
   -->
   
   # AI-assisted contributions
   
   - [X] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
   - Used OpenCode with DeepSeek V4 Pro
   
   


-- 
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]

Reply via email to