Uploaded image for project: 'ActiveMQ Classic'
  1. ActiveMQ Classic
  2. AMQ-1878

Deadlock in broker can occur when optimised dispatch is true

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • 5.1.0
    • 5.2.0
    • Broker
    • None

    Description

      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.

      Attachments

        1. ASF.LICENSE.NOT.GRANTED--queue.patch
          1 kB
          David Sitsky
        2. ASF.LICENSE.NOT.GRANTED--deadlock.txt
          8 kB
          David Sitsky

        Activity

          People

            rajdavies Robert Davies
            sits David Sitsky
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: