This is an automated email from the ASF dual-hosted git repository. cshannon pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/activemq.git
The following commit(s) were added to refs/heads/main by this push: new 3f5abd4 AMQ-6660 - Use a separate lock for lazy scheduler creation to prevent deadlocks 3f5abd4 is described below commit 3f5abd4433d3dca911ac418d899346e7dd675b7b Author: Christopher L. Shannon (cshannon) <christopher.l.shan...@gmail.com> AuthorDate: Fri Jun 25 10:54:36 2021 -0400 AMQ-6660 - Use a separate lock for lazy scheduler creation to prevent deadlocks Switch to using a dedicated lock to initialize the Scheduler object inside of ActiveMQConnection to prevent a deadlock scenario that occurs when using the intrinsic ActiveMQConnection lock. This is using double checked locking so this lock will only be contended with during lazy creation and then will rely on the volatile reference for future reads and when stopping/closing. --- .../src/main/java/org/apache/activemq/ActiveMQConnection.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnection.java b/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnection.java index 6d8ce63..5d11fb6 100644 --- a/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnection.java +++ b/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnection.java @@ -200,6 +200,7 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon protected AtomicInteger transportInterruptionProcessingComplete = new AtomicInteger(0); private long consumerFailoverRedeliveryWaitPeriod; private volatile Scheduler scheduler; + private final Object schedulerLock = new Object(); private boolean messagePrioritySupported = false; private boolean transactedIndividualAck = false; private boolean nonBlockingRedelivery = false; @@ -2383,7 +2384,7 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon // without lock contention report the closing state throw new ConnectionClosedException(); } - synchronized (this) { + synchronized (schedulerLock) { result = scheduler; if (result == null) { checkClosed();