From b788acd83466d6bd3fd264961a04fbaedc36f293 Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Fri, 17 Feb 2017 16:29:18 -0500 Subject: [PATCH] ARTEMIS-982 Fixing possible deadlock on AMQP.close & delivery https://issues.apache.org/jira/browse/ARTEMIS-982 This is fixing a possible deadlock on delivering messages while AMQP close is called for any reason. --- .../protocol/amqp/proton/AMQPConnectionContext.java | 10 ++++++---- .../protocol/amqp/proton/AMQPSessionContext.java | 8 ++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java index 0f9e89e660..c5eb108b99 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPConnectionContext.java @@ -335,11 +335,13 @@ public class AMQPConnectionContext extends ProtonInitializable { synchronized (getLock()) { connection.close(); connection.free(); - for (AMQPSessionContext protonSession : sessions.values()) { - protonSession.close(); - } - sessions.clear(); } + + for (AMQPSessionContext protonSession : sessions.values()) { + protonSession.close(); + } + sessions.clear(); + // We must force write the channel before we actually destroy the connection onTransport(handler.getTransport()); destroy(); diff --git a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPSessionContext.java b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPSessionContext.java index b45f4bb5a5..9e0b734db5 100644 --- a/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPSessionContext.java +++ b/artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPSessionContext.java @@ -16,10 +16,10 @@ */ package org.apache.activemq.artemis.protocol.amqp.proton; -import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import org.apache.activemq.artemis.protocol.amqp.broker.AMQPSessionCallback; import org.apache.activemq.artemis.protocol.amqp.client.ProtonClientSenderContext; @@ -44,9 +44,9 @@ public class AMQPSessionContext extends ProtonInitializable { private long currentTag = 0; - protected Map receivers = new HashMap<>(); + protected Map receivers = new ConcurrentHashMap<>(); - protected Map senders = new HashMap<>(); + protected Map senders = new ConcurrentHashMap<>(); protected boolean closed = false; @@ -56,7 +56,7 @@ public class AMQPSessionContext extends ProtonInitializable { this.session = session; } - protected Map serverSenders = new HashMap<>(); + protected Map serverSenders = new ConcurrentHashMap<>(); @Override public void initialise() throws Exception {