camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sergey C.(Vancouver)" <>
Subject Possible memory leak in org.apache.activemq.pool.PooledSession
Date Fri, 04 Nov 2011 19:04:48 GMT
Hello Camel & ActiveMQ uses and developers!

Here is our test setup and memory leak description.

Spring Framework 3.0.5.RELEASE
ActiveMQ 5.4.3
Camel 2.7.3

Test setup:

There are 3 actors in our test:
* ActiveMQ broker
* Client process
* Server process

Client interacts with server using InOut pattern and static reply-to queue.

Endpoint on the client side
Endpoint on the server side

How memory leak occurs:

In this scenario Camel uses 'PersistentQueueReplyManager' to receive replies
from the server process.
Specifically it uses inner class 'PersistentQueueMessageListenerContainer'
which is a child of 'DefaultMessageListenerContainer'.
Factory method 'createListenerContainer()' in line 159 creates this inner
class with cache level 'DefaultMessageListenerContainer.CACHE_SESSION' in
line 193.

So, method 'doReceiveAndExecute' in AbstractPollingMessageListenerContainer,
line 277
creates ActiveMQMessageConsumer on each invocation (
AbstractPollingMessageListenerContainer, line 277 )
When consumer object is created PersistentQueueMessageListenerContainer has
a reference to 'PolledSession',
it calls method createConsumer in PooledSession, line 235.
Object ActiveMQSession is wrapped inside PooledSession whic holds a list of
created consumers.
As a result reference to consumer object is stored inside both
'PooledSession' and inner session 'ActiveMQSession'

Memory leak occurs when method 'doReceiveAndExecute' closes consumer in the
finally section
with JmsUtils.closeMessageConsumer(consumerToClose) in
AbstractPollingMessageListenerContainer, line 365.
ActiveMQMessageConsumer has a reference to ActiveMQSession object and
detaches from it by calling
this.session.removeConsumer(this); in line 775
But 'this.session'  is a reference to ActiveMQSession object which is 'inner
session' in this PooledSession wrapper.
'PooledSession' keeps holding references to all created
ActiveMQMessageConsumer objects.

In our test setup client with 512K heap chokes after ~200'000

Workaround (for this scenario only):
* comment line 323 in PooledSession ( //consumers.add(consumer); )
* recompile 'activemq-poll' module
* install it into your local Maven repository
* enjoy millions of request/replies without memory leak

Please advice!

Sergey C.

View this message in context:
Sent from the Camel - Users mailing list archive at

View raw message