This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch ftp-leak in repository https://gitbox.apache.org/repos/asf/camel.git
commit e220e494eb29ff80fad2ba84870d8f0ec31b1ec1 Author: Claus Ibsen <[email protected]> AuthorDate: Sun Aug 6 11:14:07 2023 +0200 CAMEL-19498: camel-core - Pool for non-singleton polling consumer should be limite to capacity size, to avoid growing unlimited and leak memory. --- .../java/org/apache/camel/support/cache/ServicePool.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/core/camel-support/src/main/java/org/apache/camel/support/cache/ServicePool.java b/core/camel-support/src/main/java/org/apache/camel/support/cache/ServicePool.java index 7164a021bcb..cc4afecca11 100644 --- a/core/camel-support/src/main/java/org/apache/camel/support/cache/ServicePool.java +++ b/core/camel-support/src/main/java/org/apache/camel/support/cache/ServicePool.java @@ -85,7 +85,7 @@ abstract class ServicePool<S extends Service> extends ServiceSupport implements /** * This callback is invoked by LRUCache from a separate background cleanup thread. Therefore we mark the entries to * be evicted from this thread only, and then let SinglePool and MultiPool handle the evictions (stop the - * producer/consumer safely) when they are acquiring/releases producers/consumers. If we sop the producer/consumer + * producer/consumer safely) when they are acquiring/releases producers/consumers. If we stop the producer/consumer * from the LRUCache background thread we can have a race condition with a pooled producer may have been acquired at * the same time its being evicted. */ @@ -94,6 +94,10 @@ abstract class ServicePool<S extends Service> extends ServiceSupport implements Pool<S> p = pool.get(e); if (p != null) { p.evict(s); + if (capacity > 0 && pool.size() > capacity) { + // the pool is growing too large, so we need to stop (stop will remove itself from pool) + p.stop(); + } } else { // service no longer in a pool (such as being released twice, or can happen during shutdown of Camel etc) ServicePool.stop(s); @@ -192,15 +196,6 @@ abstract class ServicePool<S extends Service> extends ServiceSupport implements pool.values().forEach(Pool::cleanUp); } - @Override - protected void doBuild() throws Exception { - // eager load classes - SinglePool dummy = new SinglePool(); - LOG.trace("Loaded {}", dummy.getClass().getName()); - MultiplePool dummy2 = new MultiplePool(); - LOG.trace("Loaded {}", dummy2.getClass().getName()); - } - @Override protected void doStart() throws Exception { // noop
