Uploaded image for project: 'ActiveMQ Classic'
  1. ActiveMQ Classic
  2. AMQ-2838

Memory Leak when using ConnectionConsumer and a Persistent Broker

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 5.3.1
    • 5.4.0
    • Broker
    • None

    Description

      I found a memory leak in ActiveMQ when using an embedded broker with persistence (enabled by default) and using the connection to create a ConnectionConsumer. The memory leak occurs after performing the following steps:

      1. acquire a Connection (ActiveMQConnection) from a ConnectionFactory (ActiveMQConnectionFactory)
      2. use the Connection to create a ConnectionConsumer
      3. close the ConnectionConsumer
      4. close the Connection
      5. repeat steps 1 and 4 from above

      The memory leak is in org.apache.activemq.thread.Scheduler. After the last connection is closed, the embedded broker is shutdown. When this happens all AMQ threads are killed except for the "ActiveMQ Scheduler" thread. This is a Timer that contains a queue of scheduled tasks. If no brokers are running, this queue should be empty. In fact if persistence is turned off on the broker, the queue is correctly emptied after the last connection is closed. However, with persistence on, the queue does not get emptied completely.

      The memory leak is directly proportional to the number of ConnectionConsumers that are created on the connection. That is, the more ConnectionConsumers are created, the more tasks will remain on the Scheduler's task queue after the connection is closed.

      In our test environment, we create many ConnectionConsumer objects for each test and run many such tests. The memory leak accumulates quickly and we soon get an OutOfMemoryException.

      I'm attaching a junit test that illustrates the problem. The NUM_OF_CYCLES and NUM_OF_CONNECTION_CONSUMERS constants can be increased to see how the memory leak grows with increased number of iterations and ConnectionConsumer objects created, respectively. Also, persistence can be turned off on the broker url to see that the test succeeds in that case (i.e. no RAM leak).

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            rajdavies Robert Davies
            rodos77 Eugene Rodos
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment