activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Sitsky (JIRA)" <>
Subject [jira] Created: (AMQ-1878) Deadlock in broker can occur when optimised dispatch is true
Date Thu, 07 Aug 2008 03:59:52 GMT
Deadlock in broker can occur when optimised dispatch is true

                 Key: AMQ-1878
             Project: ActiveMQ
          Issue Type: Bug
          Components: Broker
    Affects Versions: 5.1.0
            Reporter: David Sitsky
            Priority: Critical
         Attachments: deadlock.txt, queue.patch

As an experiment in my application, I set optimised dispatch to be true for the broker and
discovered during the startup of my application, a deadlock could occur.  The problem is the
classic lock hierarchy issue, one thread has asked for lock A then B, another has asked for
lock B then A.

I've attached an annotated jstack output with just the deadlock information, annotated with
the locks involved.  I have also added a patch which seems to resolve the issue, but I can't
be sure if the change has other ramifications.

The problem in a nutshell is one thread calls Queue.addSubscription(), which locks dispatchLock,
and then calls wakeup/iterate() which blocks on iteratingMutex.

Another thread meanwhile has called Queue.send(), which locks iteratingMutex via wakeup/iterate(),
but then tries to call doPageIn() which requires dispatchLock.

It seems to me addSubscription() doesn't need to hold on to dispatchLock while calling wakeup/iterate(),
so I moved the wakeup() outside the usage of dispatchLock.  This ensures the lock heirarchy
between iteratingMutex and dispatchLock is always obtained in the same order.  removeSubscription()
has the same issue.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message