2 Replies Latest reply on Oct 21, 2008 10:18 AM by szhigunov

    Duplicate message after recovery rollback

    szhigunov

      I run XA transaction which includes read from remote JBM queue and write to the application database (non-XA driver). The steps are the following:
      1) Message received and processed (application database update).
      2) TM calls prepare on JBM; transaction record is created in JBM_TX table. Remote queue MBean shows MessageCount=1, DeliveringCount=1.
      3) Kill JBoss before commit phase and TM log created. Transaction record is still in JBM_TX table; remote queue MBean shows MessageCount=1, DeliveringCount=0.
      4) Start JBoss. Message received and processed. Transaction record is still in JBM_TX table and message record in JBM_MSG. Remote queue MBean shows MessageCount=0, DeliveringCount=0.
      5) TM recovery calls rollback on remote JMB XAResource (as expected). Transaction record in JBM_TX is deleted, message remains in JBM_MSG. Remote queue MBean shows MessageCount=0, DeliveringCount=0.
      6) Restart remote queue (MBean or JBoss): the same message is delivered second time. All JBM tables empty.

      My understanding, that if transacted session is used, JMS guarantees that any given message delivered only once.

      Any comments will be greatly appreciated.

      Thanks

        • 1. Re: Duplicate message after recovery rollback
          timfox

           

          "szhigunov" wrote:

          My understanding, that if transacted session is used, JMS guarantees that any given message delivered only once.



          Not quite.

          If you consume a message in a tx, *and that tx is committed* then the message is guaranteed to never be delivered again. But in your case the tx is never committed, it is rolled back. Rollback causes redelivery (see JMS spec).

          It's the recovery manager (I assume you're using JBoss TS), not JBM that decides to commit or rollback. In this case it decides to rollback. Most probably another transaction branch in the same XA transaction failed to prepare (the database update) so this would be correct behaviour.

          • 2. Re: Duplicate message after recovery rollback
            szhigunov

            I agree with what you said, but it is not what happened. In my scenario there were three delivery attempts.
            1) The first one failed and was eventually rolled-back.
            2) The second one committed. It happened as soon as JBM client started up after the failure and reconnected to the remote queue (step 4 in my post). And this is a problem since the first transaction was still in progress (not recovered yet!).
            3) The last one is a legitimate redelivery (step 6), committed. It happened after recovery of the first transaction (rollback) and queue was restarted.

            It looks like the problem is that when the client died after prepare, the queue MBean shows message as available, and delivers it right away even the JBM tables show the message as locked in transaction, waiting for TM to complete the transaction.

            I know it is hard to read such a long post, but hope you will find time to comment.

            I am running JBoss 4.2.2 + JBM 1.4.0.SP3.

            Thanks

            BTW, the same problem (two committed deliveries of the same message), happens if TM recovery commits. I can reproduce both cases.