Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
5.7.0
-
None
-
None
-
Reproduced on Windows 8, Windows Vista, MacOS X
with Oracle jdk 1.7.0_07. ActiveMQ is started embedded using RAR inside Glassfish 3.1.2.2.
Description
Originates from the forum discussion http://activemq.2283324.n4.nabble.com/RedeliveryPlugin-causes-a-deadlock-with-JobSchedulerImpl-in-ActiveMQ-5-7-0-tt4659019.html
we have RedeliveryPlugin causing thread deadlock together with JobSchedulerImpl. ActiveMQ version is 5.7.0. We activated RedeliveryPlugin in our broker config xml (see below). There two stacktraces below as well. One is from ActiveMQ VMTransport thread, which tries to send a message to a dead letter queue using RedeliveryPlugin. RedeliveryPlugin just tries to reschedule the message for redelivery and for that it calls JobSchedulerImpl and blocks on its synchronized method "schedule". On the way "consumersLock" is locked.
Another stack trace is from JobScheduler:JMS thread, which fires a job to redeliver some message and tries to send it using the same queue used by the VMTransport thread. And it blocks on that consumersLock locked by the VMTransport thread. And this occurs in JobSchedulerImpl#mainLoop method inside synchronized {} block causing a deadlock, since the VMTransport thread tries to call another synchronized method of JobSchedulerImpl. The art how RedeliveryPlugin and JobSchedulerImpl are programmed seems to be quite dangerous, since they both access the queues and try to acquire queue locks. And additionally synchronized methods of JobSchedulerImpl are called directly from RedeliveryPlugin making that to a nice source of thread deadlocks. And I see no measures taken in the code to avoid these deadlocks.
We can reproduce it quite often if we start ActiveMQ with empty stores (kahadb and scheduler stores are deleted manually from the file system before startup). But looking at the code, I would say that the problem may occur in any situation in any deployment scenario (standalone or embedded in a JEE container). It is just enough to have some Transport thread redelivering a message and the JobScheduler thread trying to fire a job at the same moment on the same queue.
And another strange thing, which is may be has nothing to do with the deadlock but is still strange, is that according to the stack trace RedeliveryPlugin tries to redeliver an expired message.
broker config and the stack traces are attached to the issue.