2 Replies Latest reply on Apr 16, 2010 5:01 AM by Andy Taylor

    Issue with Transaction Timeout and MDB's

    Andy Taylor Master

      Ok, first let me explain the scenario. Heres some psuedo code:

       

      tm.setTransactionTimeout(1);//sets the tx timeout for the tx on this thread

      endpoint.beforeDelivery(HornetQActivation.ONMESSAGE);//the tm sets the timeout on the resource(client session) and starts it

      endpoint.onMessage(msg);//call the MDB which basically sleeps for 2 seconds

      endpoint.afterDelivery();// the tm will call commit

       

       

      Ok, so what is happening is that while the onmessage in the MDB is sleeping the transaction manager times out the client session. It does this by calling rollback, the problem is that the tm does this from a different thread so during the rollback the thread gets stuck in ClientSessionImpl.waitForOnMessageToComplete() waiting for a 10 second timeout, This method only returns directly if the thread is the onmessage thread, which it isnt. At this point the consumer is stopped.

       

      While the tm rollback thread is waiting, the onmessage completes and after delivery is called. This also hangs waiting for the tm to finish calling rollback on the session, once the rollback thread completes, the commit is called and the correct exception thrown however it has been 10+ seconds and the test has timed out and failed.

       

      Does anyone have any ideas on solving this problem.

       

      One possible solution is to call setTimeout directly on the session after the tx has been started, but we would also have to check that the tm is always greater than timeout we set on the session. Seems like a bit un subtle to me.

       

      PS I asked Jonathan about this and he said there were good reasons why the rollback is done on a different thread, Jonathan, could u comment on this bit. cheers.

        • 1. Re: Issue with Transaction Timeout and MDB's
          Tim Fox Master

          This wait is valid for non XA rollback since it's illegal for rollback to be called from a different thread.

           

          However for XA rollback, which is what is occurring in this case, it's legal for the tx mgr to call this on a a different thread, and I don't think it's necessary to wait for onMessage in this case.

           

          It would a simple change in ClientSessionImpl::rollback(Xid xid) to pass a flag to consumer.clear() to determine whether to wait for on message or not.

          • 2. Re: Issue with Transaction Timeout and MDB's
            Andy Taylor Master

            Tim Fox wrote:

             

            This wait is valid for non XA rollback since it's illegal for rollback to be called from a different thread.

             

            However for XA rollback, which is what is occurring in this case, it's legal for the tx mgr to call this on a a different thread, and I don't think it's necessary to wait for onMessage in this case.

             

            It would a simple change in ClientSessionImpl::rollback(Xid xid) to pass a flag to consumer.clear() to determine whether to wait for on message or not.

            Ok, I thought about this but wasn't sure whether it was viable. I will make the changes, cheers.