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.
This commit is contained in:
Christopher L. Shannon (cshannon) 2021-06-25 10:54:36 -04:00
parent b94267c376
commit 3f5abd4433
1 changed files with 2 additions and 1 deletions

View File

@ -200,6 +200,7 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon
protected AtomicInteger transportInterruptionProcessingComplete = new AtomicInteger(0); protected AtomicInteger transportInterruptionProcessingComplete = new AtomicInteger(0);
private long consumerFailoverRedeliveryWaitPeriod; private long consumerFailoverRedeliveryWaitPeriod;
private volatile Scheduler scheduler; private volatile Scheduler scheduler;
private final Object schedulerLock = new Object();
private boolean messagePrioritySupported = false; private boolean messagePrioritySupported = false;
private boolean transactedIndividualAck = false; private boolean transactedIndividualAck = false;
private boolean nonBlockingRedelivery = false; private boolean nonBlockingRedelivery = false;
@ -2383,7 +2384,7 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon
// without lock contention report the closing state // without lock contention report the closing state
throw new ConnectionClosedException(); throw new ConnectionClosedException();
} }
synchronized (this) { synchronized (schedulerLock) {
result = scheduler; result = scheduler;
if (result == null) { if (result == null) {
checkClosed(); checkClosed();