This commit is contained in:
Clebert Suconic 2019-04-17 10:41:31 -04:00
commit 037d8a5861
3 changed files with 42 additions and 8 deletions

View File

@ -421,19 +421,31 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se
public void delete() throws JMSException {
if (session != null) {
/**
* The status of the session used to create the temporary destination is uncertain, but the JMS spec states
* that the lifetime of the temporary destination is tied to the connection so even if the originating
* session is closed the temporary destination should still be deleted. Therefore, just create a new one
* and close it after the temporary destination is deleted. This is necessary because the Core API is
* predicated on having a Core ClientSession which is encapsulated by the JMS session implementation.
*/
try (ActiveMQSession sessionToUse = (ActiveMQSession) session.getConnection().createSession()) {
boolean openedHere = false;
ActiveMQSession sessionToUse = session;
if (session.getCoreSession().isClosed()) {
sessionToUse = (ActiveMQSession)session.getConnection().createSession();
openedHere = true;
}
try {
/**
* The status of the session used to create the temporary destination is uncertain, but the JMS spec states
* that the lifetime of the temporary destination is tied to the connection so even if the originating
* session is closed the temporary destination should still be deleted. Therefore, just create a new one
* and close it after the temporary destination is deleted. This is necessary because the Core API is
* predicated on having a Core ClientSession which is encapsulated by the JMS session implementation.
*/
if (isQueue()) {
sessionToUse.deleteTemporaryQueue(this);
} else {
sessionToUse.deleteTemporaryTopic(this);
}
} finally {
if (openedHere) {
sessionToUse.close();
}
}
}
}

View File

@ -291,6 +291,10 @@ public class ServerSessionImpl implements ServerSession, FailureListener {
this.closeables.add(closeable);
}
public Map<SimpleString, TempQueueCleanerUpper> getTempQueueCleanUppers() {
return tempQueueCleannerUppers;
}
@Override
public Executor getSessionExecutor() {
return sessionExecutor;

View File

@ -26,6 +26,8 @@ import javax.jms.TemporaryTopic;
import javax.jms.TextMessage;
import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.core.server.ServerSession;
import org.apache.activemq.artemis.core.server.impl.ServerSessionImpl;
import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
import org.apache.activemq.artemis.jms.client.ActiveMQConnection;
import org.apache.activemq.artemis.tests.util.JMSTestBase;
@ -204,4 +206,20 @@ public class TemporaryDestinationTest extends JMSTestBase {
}
}
@Test
public void testForTempQueueCleanerUpperLeak() throws Exception {
try {
conn = createConnection();
Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue temporaryQueue = s.createTemporaryQueue();
temporaryQueue.delete();
for (ServerSession serverSession : server.getSessions()) {
assertEquals(0, ((ServerSessionImpl)serverSession).getTempQueueCleanUppers().size());
}
} finally {
if (conn != null) {
conn.close();
}
}
}
}