You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/08/07 07:14:40 UTC

[camel] branch camel-3.20.x updated: CAMEL-19498: camel-core - Pool for non-singleton polling consumer should be limite to capacity size, to avoid growing unlimited and leak memory. (#11013)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-3.20.x by this push:
     new b97b4ba1b1f CAMEL-19498: camel-core - Pool for non-singleton polling consumer should be limite to capacity size, to avoid growing unlimited and leak memory. (#11013)
b97b4ba1b1f is described below

commit b97b4ba1b1f1cd9802533c4570f9b298cb85748c
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Aug 7 09:13:36 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. (#11013)
---
 .../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 fe0b6fe6cf9..28ffe583fc1 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
@@ -79,7 +79,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.
      */
@@ -88,6 +88,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);
@@ -168,15 +172,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