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

KahaDBTransactionStore.removeAyncMessage may cancel addMessage when in transaction leading to unpersisted messages

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Blocker
    • Resolution: Fixed
    • 5.7.0
    • 5.9.0
    • Message Store
    • None
    • linux 64-bit, kahadb, persisted messages, cached dest, transacted

    Description

      This was very difficult to track down. It rarely occurs because a certain set of events must be occurring to trigger the bug. I have marked it a Blocker because when it does occur, it is silent and leads to a message not being persisted in the MessageStore.

      Description
      The crux of the bug is that when a rollback on a session occurs, the resulting MessageAck can overlap with the async store of the message in the KahaDB. When this occurs, the message is never persisted. Additionally, the resultant CancellationException is ignored in o.a.a.broker.region.Queue:796. The steps:

      1. a StoreQueueTask is created to add a message X. this is put on the async task queue
      2. meanwhile this message is dispatched via a prefetch subscription to a transacted consumer.
      3. the transacted consumer calls session.rollback
      4. this leads to acknowledgement of the dispatched message
      5. as a result destination.removeAsyncMessage() is called
      6. if the original add has not yet executed then it will be cancelled leading to the message never being persisted! (occurs at KahaDBStore:401)
      7. the Queue.send method uses the result future to make sure the persist happens in the store, but it ignores cancellation, so this can lead execution control to return to the sender when no persistence has occurred without an error.

      I have not been able to reproduce this in a small activemq-only test. But I can reproduce it in my environment.

      Proposed Solutions
      I'm really unsure of the solution here. Should KahaDBStore.removeAsyncMessage (line 393) check the context and only cancel tasks if it is not in a transaction context? But what would that mean in the log? Would there be a removeMessage prior to the addMessage?

      Workaround

      • turn off caching for the destination (see dest policies). this will cause messages to be added synchronously so they will not be subject to the async cancellation

      Attachments

        Activity

          People

            gtully Gary Tully
            mserrano Martin Serrano
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: