This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-2.x in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-2.x by this push: new 847b135 CAMEL-14432: Memory leak when toD is used with cacheSize < 0 (#3510) 847b135 is described below commit 847b13574d7dd11ab50d37b3a9a4fae11f8e2f87 Author: Luigi De Masi <5583341+luigidem...@users.noreply.github.com> AuthorDate: Fri Jan 24 06:03:11 2020 +0100 CAMEL-14432: Memory leak when toD is used with cacheSize < 0 (#3510) --- .../java/org/apache/camel/impl/ProducerCache.java | 36 ++++++++-------------- 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/camel-core/src/main/java/org/apache/camel/impl/ProducerCache.java b/camel-core/src/main/java/org/apache/camel/impl/ProducerCache.java index 9531494..36aa1cc 100644 --- a/camel-core/src/main/java/org/apache/camel/impl/ProducerCache.java +++ b/camel-core/src/main/java/org/apache/camel/impl/ProducerCache.java @@ -353,7 +353,7 @@ public class ProducerCache extends ServiceSupport { T answer = null; // get the producer and we do not mind if its pooled as we can handle returning it back to the pool - Producer producer = doGetProducer(endpoint, true); + Producer producer = acquireProducer(endpoint); if (producer == null) { if (isStopped()) { @@ -372,17 +372,11 @@ public class ProducerCache extends ServiceSupport { exchange.setException(e); } } finally { - if (producer instanceof ServicePoolAware) { - // release back to the pool - pool.release(endpoint, producer); - } else if (!producer.isSingleton()) { - // stop and shutdown non-singleton producers as we should not leak resources - try { - ServiceHelper.stopAndShutdownService(producer); - } catch (Exception e) { - // ignore and continue - LOG.warn("Error stopping/shutting down producer: {}", producer, e); - } + try { + releaseProducer(endpoint, producer); + } catch (Exception e) { + // ignore and continue + LOG.warn("Error stopping/shutting down producer: " + producer, e); } } @@ -407,7 +401,7 @@ public class ProducerCache extends ServiceSupport { Producer target; try { // get the producer and we do not mind if its pooled as we can handle returning it back to the pool - target = doGetProducer(endpoint, true); + target = target = acquireProducer(endpoint); if (target == null) { if (isStopped()) { @@ -450,17 +444,11 @@ public class ProducerCache extends ServiceSupport { EventHelper.notifyExchangeSent(exchange.getContext(), exchange, endpoint, timeTaken); } - if (producer instanceof ServicePoolAware) { - // release back to the pool - pool.release(endpoint, producer); - } else if (!producer.isSingleton()) { - // stop and shutdown non-singleton producers as we should not leak resources - try { - ServiceHelper.stopAndShutdownService(producer); - } catch (Exception e) { - // ignore and continue - LOG.warn("Error stopping/shutting down producer: {}", producer, e); - } + try { + releaseProducer(endpoint, producer); + } catch (Exception e) { + // ignore and continue + LOG.warn("Error stopping/shutting down producer: " + producer, e); } } finally { callback.done(doneSync);