1 2 Previous Next 16 Replies Latest reply on Nov 5, 2013 11:04 PM by clebert.suconic

    session is already doing work in a transaction XidImpl

    1117866v

      Hello,

       

      I am using hornetQ-core-2.2.24.jar and hornet-jms-2.2.23.final.jar on Jboss6.0.1. We have a 3 node standalone hornetQ cluster, a timer singleton bean on one of the node reads database records and generates JMS messages containing the database ID to a queue. The Queue consumer consumes these messages and runs business logic etc etc.


      We have performing load test and we see loads of exceptions, I was hoping to understand from the group how and why these exceptions occur. the following exception is seen :

      0:15:29,990 ERROR [org.hornetq.core.client.impl.ClientSessionImpl] (Thread-1054 (HornetQ-client-global-threads-67418210)) XA operation failed Cannot start, session is already doing work in a transaction
      XidImpl (283600144 bq:0.0.0.0.0.0.0.0.0.0.-1.-1.10.-75.62.83.-82.44.63.-41.82.106.-122.91.0.5.-118.-47.0.0.0.0.0.0.0.0 formatID:131077 gtxid:0.0.0.0.0.0.0.0.0.0.-1.-1.10.-75.62.83.-82.44.63.-41.82.106.-12
      2.91.0.5.-118.-49.49 base64:AAAAAAAAAAAAAP__CrU-U64sP9dSaoZbAAWK0QAAAAAAAAAAAAAAAAAAAAAAAP__CrU-U64sP9dSaoZbAAWKzzEHAgIA code:-6

       

      If I am understanding this error right, does it mean the session is being reused ? session being not threadsafe, am I doing something wrong in configuration/code? do let me know what is needed, I will have it furnished here.

       

      I am using the following code to fetch CF :

      The timer bean uses following code to fetch a connectionfactory

                  String[] hostnames =  {"node1", "node2", "node3"};

                  TransportConfiguration[] servers = new TransportConfiguration[hostnames.length];

                  for (int i = 0; i < servers.length; i++) {

                      String host = hostnames[i];

                      Map<String, Object> map = new HashMap<String, Object>();

                      map.put("host", host);

                      map.put("port", "5445");

                      TransportConfiguration server = new TransportConfiguration(NettyConnectorFactory.class.getName(), map);

                      servers[i] = server;

                  }

       

                  // Initialize a native hornetQ connection factory with knowledge of each node

                  HornetQConnectionFactory connectionFactory

                          =  HornetQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, servers);

                  cf = (ConnectionFactory)connectionFactory; // Cast it to the JMS interface

       

      there after the code to get connection/session/queue/sender/ etc..

       

      Thanks..

        • 1. Re: session is already doing work in a transaction XidImpl
          ataylor

          no JMS sessions are not thread safe so you can only have one transaction running at any one single time.

           

          Also how are you using XA?

          • 2. Re: session is already doing work in a transaction XidImpl
            1117866v

            Thanks Andy for confirming that JMS sessions are not thread safe, I am calling close() on sender, session and connection only the CF is being reused.

             

            I am marking the connection-factory as <xa>true</xa>, would that be sufficient to enlist JMS as XA resource. Also I am fetching a XA_CF from hornetQJMSClient.

            • 3. Re: session is already doing work in a transaction XidImpl
              ataylor

              if you arent looking up the pooled connection factory then you wont be using XA, the pooled cf is managed by the AS you have to use this for XA to work. also note that the AS does this for JEE components, I dot know much about timer beans but Im assuming that there will be XA support.

               

              saying all that Im confused by the error as since your not using XA know XA calls should be made, unless you are doing them.

              1 of 1 people found this helpful
              • 4. Re: session is already doing work in a transaction XidImpl
                1117866v

                Thanks I didnt know that pooled-connection-factories are needed for JMS XA. I configured a pooled-connection-factory, is there a way I can make hornetQJMSClient fetch a XA_CF from JNDI? only then it would be managed correct?

                 

                Also, what use is JMSFactoryType.XA_CF when used with HornetQJMSClient?

                • 5. Re: session is already doing work in a transaction XidImpl
                  jbertram

                  First of all, please clarify why you need XA.  From your description it doesn't appear that XA is even necessary since your transaction only involves one resource (i.e. JMS).

                   

                  Second, both a pooled-connection-factory and a normal JMS connection factory can be XA.  However, the pooled-connection-factory has additional functionality to enlist the XA resource into the parent JTA transaction, etc. whereas the normal JMS connection factory just provides a raw javax.jms.XAConnectionFactory implementation which isn't terribly useful in and of itself.

                   

                  Third, org.hornetq.api.jms.HornetQJMSClient has utility functions for instantiating a JMS connection factory.  If you want to look-up a connection factory from JNDI then you should simply inject it or use javax.naming.InitialContext.

                   

                  Last, when using org.hornetq.api.jms.HornetQJMSClient with org.hornetq.api.jms.JMSFactoryType.XA_CF you would get a raw javax.jms.XAConnectionFactory implementation.  If you actually wanted to use that in a real XA transaction then you'd have to get a javax.transaction.xa.XAResource and enlist it into the JTA transaction using the transaction manager. 

                  • 6. Re: session is already doing work in a transaction XidImpl
                    1117866v

                    Yes, you are right. XA functionality is not required in this usecase I mentioned above. I was answering Andy's Questions on How how I am using XA and this discussion went off on a tangent and helped me understand things I didn't know. 

                     

                    To my original question and exception started to happen when I changed my implementation from fetching a CF from InitialContext to fetching CF from HornetQJMSClient (mentioned in the code above.)

                     

                    I had to change my implementation to HornetQJMSClient and standalone cluster nodes coz of failover not happening from a live to live node. if you can advice how I would solve distribution problem at the same time avoiding the above exception.

                     

                    • 7. Re: session is already doing work in a transaction XidImpl
                      jbertram

                      I don't see how changing from a JNDI lookup to direct instantiation would necessarily yield any different behavior.

                       

                      In any event, fail-over between live nodes is not supported any any context.  Fail-over is only supported between a live and a backup.

                      • 8. Re: session is already doing work in a transaction XidImpl
                        1117866v

                        Yes, thats my point as well. Why would the CF be treated as participating in XA Transaction when its I am fetching a NON XA CF (see code above)? is it coz I the MDB are in a CMT?

                        Why is ClientSessionImpl calling a start on a NON XA CF?

                        • 9. Re: session is already doing work in a transaction XidImpl
                          1117866v

                          Any hints as to why a session is being used in multiple transactions? ask me questions I can answer to get this resolved.

                          • 10. Re: session is already doing work in a transaction XidImpl
                            ataylor

                            not unless you can provide with some sort of runnable example that we can test.

                            • 11. Re: session is already doing work in a transaction XidImpl
                              1117866v

                              I am working on a prototype that can simulate this problem. My observation tells me this exception occurs on the Consumer side and not the producer. 

                               

                              Can you help with the location of source for hornetq-core-2.2.24.BZ928936.jar. Also, when the above exception occurs we notice JTA throwing a XAException.

                               

                              13:05:41,609 ERROR [org.hornetq.core.client.impl.ClientSessionImpl] (Thread-358 (HornetQ-client-global-threads-1764447156)) XA operation failed Cannot start, session is already doing work in a transaction XidImpl (953064683 bq:0.0.0.0.0.0.0.0.0.0.-1.-1.10.-75.62.84.-95.96.-78.-115.82.121.84.-78.0.2.79.88.0.0.0.0.0.0.0.0 formatID:131077 gtxid:0.0.0.0.0.0.0.0.0.0.-1.-1.10.-75.62.84.-95.96.-78.-115.82.121.84.-78.0.2.79.87.49 base64:AAAAAAAAAAAAAP__CrU-VKFgso1SeVSyAAJPWAAAAAAAAAAAAAAAAAAAAAAAAP__CrU-VKFgso1SeVSyAAJPVzEHAgIA code:-6

                              13:05:41,610 WARN  [com.arjuna.ats.jta] (Thread-358 (HornetQ-client-global-threads-1764447156)) ARJUNA016061: TransactionImple.enlistResource - XAResource.start returned: XAException.XAER_PROTO for < formatId=131077, gtrid_length=29, bqual_length=36, tx_uid=0:ffff0ab53e54:-5e9f4d73:527954b2:25788, node_name=1, branch_uid=0:ffff0ab53e54:-5e9f4d73:527954b2:25789, subordinatenodename=null, eis_name=unknown eis name >: javax.transaction.xa.XAException

                                      at org.hornetq.core.client.impl.ClientSessionImpl.start(ClientSessionImpl.java:1676) [hornetq-core-2.2.24.BZ928936.jar:2.2.24.BZ928936 (HQ_2_2_24_BZ928936, 122)]

                                      at org.hornetq.core.client.impl.DelegatingSession.start(DelegatingSession.java:513) [hornetq-core-2.2.24.BZ928936.jar:2.2.24.BZ928936 (HQ_2_2_24_BZ928936, 122)]

                                      at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.enlistResource(TransactionImple.java:636) [jbossjts-4.16.6.Final-redhat-1.jar:]

                                      at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.enlistResource(TransactionImple.java:397) [jbossjts-4.16.6.Final-redhat-1.jar:]

                                      at org.jboss.as.ejb3.inflow.MessageEndpointInvocationHandler.beforeDelivery(MessageEndpointInvocationHandler.java:112) [jboss-as-ejb3-7.1.3.Final-redhat-4-bz-911406.jar:7.1.3.Final-redhat-4]

                                      at sun.reflect.GeneratedMethodAccessor357.invoke(Unknown Source) [:1.6.0_45]

                                      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_45]

                                      at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_45]

                                      at org.jboss.as.ejb3.inflow.AbstractInvocationHandler.handle(AbstractInvocationHandler.java:60) [jboss-as-ejb3-7.1.3.Final-redhat-4-bz-911406.jar:7.1.3.Final-redhat-4]

                                      at org.jboss.as.ejb3.inflow.MessageEndpointInvocationHandler.doInvoke(MessageEndpointInvocationHandler.java:138) [jboss-as-ejb3-7.1.3.Final-redhat-4-bz-911406.jar:7.1.3.Final-redhat-4]

                                      at org.jboss.as.ejb3.inflow.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:73) [jboss-as-ejb3-7.1.3.Final-redhat-4-bz-911406.jar:7.1.3.Final-redhat-4]

                                      at com.sun.proxy.$Proxy103.beforeDelivery(Unknown Source)

                                      at org.hornetq.ra.inflow.HornetQMessageHandler.onMessage(HornetQMessageHandler.java:307)

                                      at org.hornetq.core.client.impl.ClientConsumerImpl.callOnMessage(ClientConsumerImpl.java:1036) [hornetq-core-2.2.24.BZ928936.jar:2.2.24.BZ928936 (HQ_2_2_24_BZ928936, 122)]

                                      at org.hornetq.core.client.impl.ClientConsumerImpl.access$400(ClientConsumerImpl.java:52) [hornetq-core-2.2.24.BZ928936.jar:2.2.24.BZ928936 (HQ_2_2_24_BZ928936, 122)]

                                      at org.hornetq.core.client.impl.ClientConsumerImpl$Runner.run(ClientConsumerImpl.java:1181) [hornetq-core-2.2.24.BZ928936.jar:2.2.24.BZ928936 (HQ_2_2_24_BZ928936, 122)]

                                      at org.hornetq.utils.OrderedExecutorFactory$OrderedExecutor$1.run(OrderedExecutorFactory.java:100) [hornetq-core-2.2.24.BZ928936.jar:2.2.24.BZ928936 (HQ_2_2_24_BZ928936, 122)]

                                      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) [rt.jar:1.6.0_45]

                                      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) [rt.jar:1.6.0_45]

                                      at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_45]

                              • 12. Re: session is already doing work in a transaction XidImpl
                                jbertram

                                Please format your comment so that it's readable.

                                 

                                The source for that branch is at https://github.com/hornetq/hornetq-oneoffs/tree/oneoff-HornetQ_2.2.24_2.2.x_BZ928936.

                                • 13. Re: session is already doing work in a transaction XidImpl
                                  clebert.suconic

                                  With pooled connection factories you get transaction integration for free as Andy said

                                   

                                   

                                  If you use a regular XA connection factory you have to enlist things yourself and use the transaction manager. You will have to look at the TM method to enlist and delist transactions.

                                  • 14. Re: session is already doing work in a transaction XidImpl
                                    1117866v

                                    Thanks Justin, formatted post.

                                    1 2 Previous Next