From 955af96fe9e3d6a7fb518fb0161368306c2d0376 Mon Sep 17 00:00:00 2001 From: Martyn Taylor Date: Wed, 29 Mar 2017 13:45:45 +0100 Subject: [PATCH] ARTEMIS-1082 Catch Create Queue race in OpenWire --- .../protocol/openwire/amq/AMQSession.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/amq/AMQSession.java b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/amq/AMQSession.java index 7a8ed3bf26..bd07251187 100644 --- a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/amq/AMQSession.java +++ b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/amq/AMQSession.java @@ -23,6 +23,7 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException; import org.apache.activemq.artemis.api.core.RoutingType; import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.core.paging.PagingStore; @@ -176,16 +177,20 @@ public class AMQSession implements SessionCallback { BindingQueryResult bindingQuery = server.bindingQuery(queueName); QueueQueryResult queueBinding = server.queueQuery(queueName); - boolean isAutoCreate = bindingQuery.isExists() ? true : bindingQuery.isAutoCreateQueues(); - - if (!queueBinding.isExists()) { - if (isAutoCreate) { - server.createQueue(queueName, RoutingType.ANYCAST, queueName, null, true, isTemporary); - connection.addKnownDestination(queueName); - } else { - hasQueue = false; + try { + if (!queueBinding.isExists()) { + if (bindingQuery.isAutoCreateQueues()) { + server.createQueue(queueName, RoutingType.ANYCAST, queueName, null, true, isTemporary); + connection.addKnownDestination(queueName); + } else { + hasQueue = false; + } } + } catch (ActiveMQQueueExistsException e) { + // In case another thread created the queue before us but after we did the binding query + hasQueue = true; } + } return hasQueue; }