I have run the java systests with the JCarder agent attached. When using AMQP 0-9, JCarder detected a potential deadlock when the following are done concurrently:
- Close a consumer from an application thread.
- Call Connection.createSession from an application thread.
- Call Connection.createSession inside MessageListener.onMessage().
Here is a sketch of the deadlock scenario:
lock AMQConnection._sessionCreationLock BLOCKED BY applicationThread1
lock AMQConnection.getFailoverMutex() BLOCKED BY applicationThread2
lock AMQSession._messageDeliveryLock BLOCKED BY Dispatcher-1-Conn-780
Interestingly, AMQConnectionDelegate_0_10.executeRetrySupport(..) does not acquire the failover mutex (I have no idea if it should) so is not susceptible to this deadlock.
I've attached the GraphViz .dot file that JCarder generated when it detected this problem.
Note that this problem is similar to
QPID-4574 and QPID-5118 so might be fixed by a single commit.