8 Replies Latest reply on Feb 25, 2005 5:31 PM by javajedi

    Trying to change Tx in enlist

      JBoss 4.0.1
      Oracle 9
      Mandrake Linux 10

      I'm getting the following exception from my app on an infrequent and random basis:

      org.jboss.util.NestedSQLException: Unchecked throwable in managedConnectionReconnected(); - nested throwable: (java.lang.IllegalStateException: Trying to change Tx in enlist!); - nested throwable: (org.jboss.resource.JBossResourceException: Unchecked throwable in managedConnectionReconnected(); - nested throwable: (java.lang.IllegalStateException: Trying to change Tx in enlist!))
      at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:106)
      at com.hmsonline.common.useragent.ResponseCacher.requestToIdentifierString(ResponseCacher.java:413)
      ... 8 more
      Caused by: org.jboss.resource.JBossResourceException: Unchecked throwable in managedConnectionReconnected(); - nested throwable: (java.lang.IllegalStateException: Trying to change Tx in enlist!)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2.rethrowAsResourceException(BaseConnectionManager2.java:102)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:463)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:846)
      at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:102)
      ... 9 more
      Caused by: java.lang.IllegalStateException: Trying to change Tx in enlist!
      at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener.enlist(TxConnectionManager.java:419)
      at org.jboss.resource.connectionmanager.TxConnectionManager.managedConnectionReconnected(TxConnectionManager.java:324)
      at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:454)
      ... 11 more


      It certainly seems to be caused by a race condition. I do have multiple threads taking part in the same transaction simultaneously. Any suggestions on how I might start to track down the problem? Thanks.

        • 1. Re: Trying to change Tx in enlist

          I've also started seeing this exception mixed in with the others. Looks like it's probably related. All I'm doing is committing my transaction. The only thing unusual that might apply to my situation is that I've got multiple threads using the same transaction.

          ******** ERROR Feb 19 13:48:34 [resource.connectionmanager.TxConnectionManager] - There is something wrong with the pooling?java.lang.IllegalStateException: afterCompletion called with wrong tx! Expected: null, actual: TransactionImpl:XidImpl[FormatId=257, GlobalId=redback.hmsonline.com/16116, BranchQual=, localId=16116] at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener$TxRemover.afterCompletion(TxConnectionManager.java:589) at org.jboss.resource.connectionmanager.TransactionSynchronizer.invokeAfter(TransactionSynchronizer.java:181) at org.jboss.resource.connectionmanager.TransactionSynchronizer.afterCompletion(TransactionSynchronizer.java:142) at org.jboss.tm.TransactionImpl.doAfterCompletion(TransactionImpl.java:1418) at org.jboss.tm.TransactionImpl.completeTransaction(TransactionImpl.java:1090) at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:349)

          • 2. Re: Trying to change Tx in enlist

            This same question was asked a couple a weeks ago
            (concurrent use a transaction is not currently supported by JBossJTA)

            • 3. Re: Trying to change Tx in enlist

              That's really scary. I've got a production application that depends on that. I'm looking at the JTA specification and Section 3.2 states "Multiple threads may concurrently be associated with the same global transaction." Does this mean that this is a bug in JBoss, or am I missing something? Can you please post a pointer to the previous question that you referenced?

              • 4. Re: Trying to change Tx in enlist

                You can use search just as well as I can, but I will summarise.

                Multithreaded use of a transaction is disallowed in the EJB spec
                (see transaction diamonds). Parts of the EJB spec depend upon one thread per
                transaction for correct behaviour.

                Outside the EJB spec, it requires a transaction reconciliation process
                to either wait or fail the commit (policy decision) if one thread tries
                to commit while another thread in the transaction is still processing.

                Feature Request where you can vote:
                http://jira.jboss.com/jira/browse/JBAS-1421
                Francisco Reverbel is already working on an OTS TM for JBoss.

                • 5. Re: Trying to change Tx in enlist

                  Thanks for the info. I can see why they disallow this in the EJB spec, but the code I'm using to do this is not an EJB. This still sounds like a bug to me since the JTA spec says that it should be allowed.

                  • 6. Re: Trying to change Tx in enlist

                    I wish people would stop screaming bug at the top of the hat.

                    It is only a bug when you can clearly point to *MUST* in the spec and have
                    a test case that shows it does not.

                    The JTS/OTS spec requires this behaviour, the JTA spec *allows* it such
                    that OTS TMs can be JTA compliant.
                    The JTA spec allows the opposite, even down to the thread that started the
                    transaction must commit it (i.e. you cannot even suspend on one thread
                    and resume on another).

                    The JTS spec is an "optional" spec in J2EE and JBossTM does not
                    currently implement it.
                    All you are required to do in J2EE is trap transaction progogation over RMI/IIOP
                    and throw a RemoteException saying you don't support it.

                    • 7. Re: Trying to change Tx in enlist

                       

                      "adrian@jboss.org" wrote:

                      The JTS spec is an "optional" spec in J2EE and JBossTM does not
                      currently implement it.
                      All you are required to do in J2EE is trap transaction progogation over RMI/IIOP
                      and throw a RemoteException saying you don't support it.


                      In fact the problem is that you have an alternate mechanism for
                      transaction propogation that bypasses our checking.

                      If it is any concilation, we are having a project meeting about the JTS/TM
                      roadmap on Monday before JBossWorld.

                      • 8. Re: Trying to change Tx in enlist

                        It's "drop of a hat" and I wasn't screaming. ;-)

                        I think I found the other discussion thread you were referring to at http://www.jboss.org/index.html?module=bb&op=viewtopic&t=58762.

                        I won't bother creating a test case since it sounds like nobody would expect concurrent use of transactions to work anyway. I dug further into the JTA spec and read "Note that some transaction manager implementations allow a suspended transaction to be resumed by a different thread. This feature is not required by JTA." in section 3.2.3. That alone is enough to convince me that this is not a bug. That doesn't help my disappointment though. Thanks for the replies Adrian.