From efc857fc1f679631dcb98b9bf6b13317e7a80785 Mon Sep 17 00:00:00 2001 From: gtully Date: Wed, 19 Jun 2019 10:29:11 +0100 Subject: [PATCH] AMQ-7233 - ensure sessions are cleaned up on pooledconnection.close before temp dests to ensure temp dests actually get deleted, fix and test --- .../activemq/jms/pool/PooledConnection.java | 2 +- ...nFactoryWithTemporaryDestinationsTest.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/activemq-jms-pool/src/main/java/org/apache/activemq/jms/pool/PooledConnection.java b/activemq-jms-pool/src/main/java/org/apache/activemq/jms/pool/PooledConnection.java index 111e730dfb..00911ece87 100644 --- a/activemq-jms-pool/src/main/java/org/apache/activemq/jms/pool/PooledConnection.java +++ b/activemq-jms-pool/src/main/java/org/apache/activemq/jms/pool/PooledConnection.java @@ -81,8 +81,8 @@ public class PooledConnection implements TopicConnection, QueueConnection, Poole @Override public void close() throws JMSException { - this.cleanupConnectionTemporaryDestinations(); this.cleanupAllLoanedSessions(); + this.cleanupConnectionTemporaryDestinations(); if (this.pool != null) { this.pool.decrementReferenceCount(); this.pool = null; diff --git a/activemq-jms-pool/src/test/java/org/apache/activemq/jms/pool/PooledConnectionFactoryWithTemporaryDestinationsTest.java b/activemq-jms-pool/src/test/java/org/apache/activemq/jms/pool/PooledConnectionFactoryWithTemporaryDestinationsTest.java index 86b4e27932..d879580c57 100644 --- a/activemq-jms-pool/src/test/java/org/apache/activemq/jms/pool/PooledConnectionFactoryWithTemporaryDestinationsTest.java +++ b/activemq-jms-pool/src/test/java/org/apache/activemq/jms/pool/PooledConnectionFactoryWithTemporaryDestinationsTest.java @@ -19,6 +19,7 @@ package org.apache.activemq.jms.pool; import static org.junit.Assert.assertEquals; import javax.jms.Connection; +import javax.jms.MessageConsumer; import javax.jms.Queue; import javax.jms.Session; import javax.jms.Topic; @@ -119,6 +120,24 @@ public class PooledConnectionFactoryWithTemporaryDestinationsTest extends JmsPoo assertEquals(0, countBrokerTemporaryTopics()); } + @Test(timeout = 60000) + public void testTemporaryQueueLeakAfterConnectionCloseWithConsumer() throws Exception { + Connection pooledConnection = null; + Session session = null; + Queue tempQueue = null; + for (int i = 0; i < 2; i++) { + pooledConnection = pooledFactory.createConnection(); + session = pooledConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); + tempQueue = session.createTemporaryQueue(); + MessageConsumer consumer = session.createConsumer(tempQueue); + consumer.receiveNoWait(); + LOG.info("Created queue named: " + tempQueue.getQueueName()); + pooledConnection.close(); + } + + assertEquals(0, countBrokerTemporaryQueues()); + } + private int countBrokerTemporaryQueues() throws Exception { return ((RegionBroker) brokerService.getRegionBroker()).getTempQueueRegion().getDestinationMap().size(); }