Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.1.1, 5.0.0
    • Component/s: None
    • Labels:
      None
    • Environment:

      Java, JDK 1.4, Windows, Atomikos TransactionsEssentials for the JTA/XA part

      Description

      XAResource.recover seems to fail for 4.x of ActiveMQ:

      ERROR IN RECOVERY [thread: SimpleAsyncTaskExecutor-3] on: 06-11-16 08:43:35,152
      [Lorg.apache.activemq.command.DataStructure; [thread: SimpleAsyncTaskExecutor-3] on: 06-11-16 08:43:35,152
      at: org.apache.activemq.TransactionContext.recover(TransactionContext.java:508) [thread: SimpleAsyncTaskExecutor-3] on: 06-11-16 08:43:35,152
      at: com.atomikos.datasource.xa.XATransactionalResource.recover(Unknown Source) [thread: SimpleAsyncTaskExecutor-3] on: 06-11-16 08:43:35,152
      at: com.atomikos.datasource.xa.XATransactionalResource.endRecovery(Unknown Source) [thread: SimpleAsyncTaskExecutor-3] on: 06-11-16 08:43:35,152
      at: com.atomikos.icatch.imp.TransactionServiceImp.recover(Unknown Source) [thread: SimpleAsyncTaskExecutor-3] on: 06-11-16 08:43:35,153
      at: com.atomikos.datasource.xa.XATransactionalResource.setRecoveryService(Unknown Source) [thread: SimpleAsyncTaskExecutor-3] on: 06-11-16 08:43:35,153
      at: com.atomikos.icatch.system.Configuration.addResource(Unknown Source) [thread: SimpleAsyncTaskExecutor-3] on: 06-11-16 08:43:35,153
      at: com.atomikos.jms.QueueConnectionFactoryBean.checkSetup(Unknown Source) [thread: SimpleAsyncTaskExecutor-3] on: 06-11-16 08:43:35,153
      at: com.atomikos.jms.QueueConnectionFactoryBean.createQueueConnection(Unknown Source) [thread: SimpleAsyncTaskExecutor-3] on: 06-11-16 08:43:35,153
      at: com.atomikos.jms.QueueConnectionFactoryBean.createConnection(Unknown Source) [thread: SimpleAsyncTaskExecutor-3] on: 06-11-16 08:43:35,153

      Also see http://www.atomikos-support.com/forums/viewtopic.php?t=351 (where I borrowed this stack trace from). We have seen similar things in other applications that tried to use ActiveMQ. I think this is a class cast error in ActiveMQ...

      With 3.1 there is no problem.

      1. pom.xml
        4 kB
        james strachan

        Issue Links

          Activity

          Hide
          james strachan added a comment -

          Does this happen on 4.0.2 as well?

          Show
          james strachan added a comment - Does this happen on 4.0.2 as well?
          Hide
          Guy Pardon added a comment -

          Yes, 4.0.2 too.

          Below is a test program (you need the atomikos jars in the classpath, as well as all activemq jars). Note that the only atomikos dependency is the Xid format.

          Guy

          package activemqtest;

          import javax.jms.MessageConsumer;
          import javax.jms.XAConnection;
          import javax.jms.XASession;
          import javax.transaction.xa.XAResource;
          import javax.transaction.xa.Xid;

          import org.apache.activemq.ActiveMQXAConnectionFactory;
          import org.apache.activemq.command.ActiveMQQueue;

          import com.atomikos.datasource.xa.DefaultXidFactory;

          public class XATest {

          public static void main ( String[] args ) throws Exception

          { String url = "tcp://localhost:61616"; String qName = "MyQueue"; int timeout = 5; DefaultXidFactory xidFactory = new DefaultXidFactory(); ActiveMQXAConnectionFactory xacf = new ActiveMQXAConnectionFactory(); xacf.setBrokerURL ( url ); ActiveMQQueue queue = new ActiveMQQueue(); queue.setPhysicalName ( qName ); XAConnection xaconn = xacf.createXAConnection(); xaconn.start(); XASession session = xaconn.createXASession(); XAResource xares = session.getXAResource(); MessageConsumer receiver = session.getSession().createConsumer ( queue ); xares.recover ( XAResource.TMSTARTRSCAN ); xares.recover ( XAResource.TMNOFLAGS ); xares.setTransactionTimeout ( timeout ); xares.isSameRM ( xares ); Xid xid = xidFactory.createXid ( "part1" , "part2"); xares.start ( xid , XAResource.TMNOFLAGS ); receiver.receive ( timeout ); xares.end ( xid , XAResource.TMSUCCESS ); xares.rollback ( xid ); }

          }

          Show
          Guy Pardon added a comment - Yes, 4.0.2 too. Below is a test program (you need the atomikos jars in the classpath, as well as all activemq jars). Note that the only atomikos dependency is the Xid format. Guy package activemqtest; import javax.jms.MessageConsumer; import javax.jms.XAConnection; import javax.jms.XASession; import javax.transaction.xa.XAResource; import javax.transaction.xa.Xid; import org.apache.activemq.ActiveMQXAConnectionFactory; import org.apache.activemq.command.ActiveMQQueue; import com.atomikos.datasource.xa.DefaultXidFactory; public class XATest { public static void main ( String[] args ) throws Exception { String url = "tcp://localhost:61616"; String qName = "MyQueue"; int timeout = 5; DefaultXidFactory xidFactory = new DefaultXidFactory(); ActiveMQXAConnectionFactory xacf = new ActiveMQXAConnectionFactory(); xacf.setBrokerURL ( url ); ActiveMQQueue queue = new ActiveMQQueue(); queue.setPhysicalName ( qName ); XAConnection xaconn = xacf.createXAConnection(); xaconn.start(); XASession session = xaconn.createXASession(); XAResource xares = session.getXAResource(); MessageConsumer receiver = session.getSession().createConsumer ( queue ); xares.recover ( XAResource.TMSTARTRSCAN ); xares.recover ( XAResource.TMNOFLAGS ); xares.setTransactionTimeout ( timeout ); xares.isSameRM ( xares ); Xid xid = xidFactory.createXid ( "part1" , "part2"); xares.start ( xid , XAResource.TMNOFLAGS ); receiver.receive ( timeout ); xares.end ( xid , XAResource.TMSUCCESS ); xares.rollback ( xid ); } }
          Hide
          Shoaib Akhtar added a comment -

          Hi,
          I am also using atomikos with activemq and facing the same problem, i ran the above test with logging turned on and with level Debug and my log output is as follows.

          DEBUG [main] WireFormatNegotiator.start(65) | Sending: WireFormatInfo { version=1, properties=

          {TightEncodingEnabled=true, TcpNoDelayEnabled=true, SizePrefixDisabled=false, StackTraceEnabled=true, MaxInactivityDuration=30000, CacheEnabled=true}

          , magic=[A,c,t,i,v,e,M,Q]}
          DEBUG [ActiveMQ Transport: tcp://localhost/127.0.0.1:61616] WireFormatNegotiator.onCommand(95) | Received WireFormat: WireFormatInfo { version=1, properties=

          {StackTraceEnabled=true, TightEncodingEnabled=true, TcpNoDelayEnabled=true, SizePrefixDisabled=false, MaxInactivityDuration=30000, CacheEnabled=true}

          , magic=[A,c,t,i,v,e,M,Q]}
          DEBUG [ActiveMQ Transport: tcp://localhost/127.0.0.1:61616] WireFormatNegotiator.onCommand(102) | tcp://localhost/127.0.0.1:61616 before negotiation: OpenWireFormat

          {version=1, cacheEnabled=false, stackTraceEnabled=false, tightEncodingEnabled=false, sizePrefixDisabled=false}

          DEBUG [ActiveMQ Transport: tcp://localhost/127.0.0.1:61616] WireFormatNegotiator.onCommand(113) | tcp://localhost/127.0.0.1:61616 after negotiation: OpenWireFormat

          {version=1, cacheEnabled=true, stackTraceEnabled=true, tightEncodingEnabled=true, sizePrefixDisabled=false}

          DEBUG [main] TransactionContext.recover(503) | Recover: 16777216

          and the exception was as follows.

          Exception in thread "main" java.lang.ClassCastException: [Lorg.apache.activemq.command.DataStructure;
          at org.apache.activemq.TransactionContext.recover(TransactionContext.java:508)
          at activemqtest.XATest.main(XATest.java:27)

          It seems to me that in case when activemq has nothing to recover as there is no transaction to recover then the code has problems and the offending line is

          return (XATransactionId[]) receipt.getData();

          And my ide is on evaluating this line shows me
          receipt.getData() = org.apache.activemq.command.DataStructure[0]

          and it seems to me that this array of DataStructure contains nothing and it is just instantiated without any elements and the class used to instatiate is not the instance of XATransactionId, i think it might work if there is something to recover.

          Show
          Shoaib Akhtar added a comment - Hi, I am also using atomikos with activemq and facing the same problem, i ran the above test with logging turned on and with level Debug and my log output is as follows. DEBUG [main] WireFormatNegotiator.start(65) | Sending: WireFormatInfo { version=1, properties= {TightEncodingEnabled=true, TcpNoDelayEnabled=true, SizePrefixDisabled=false, StackTraceEnabled=true, MaxInactivityDuration=30000, CacheEnabled=true} , magic= [A,c,t,i,v,e,M,Q] } DEBUG [ActiveMQ Transport: tcp://localhost/127.0.0.1:61616] WireFormatNegotiator.onCommand(95) | Received WireFormat: WireFormatInfo { version=1, properties= {StackTraceEnabled=true, TightEncodingEnabled=true, TcpNoDelayEnabled=true, SizePrefixDisabled=false, MaxInactivityDuration=30000, CacheEnabled=true} , magic= [A,c,t,i,v,e,M,Q] } DEBUG [ActiveMQ Transport: tcp://localhost/127.0.0.1:61616] WireFormatNegotiator.onCommand(102) | tcp://localhost/127.0.0.1:61616 before negotiation: OpenWireFormat {version=1, cacheEnabled=false, stackTraceEnabled=false, tightEncodingEnabled=false, sizePrefixDisabled=false} DEBUG [ActiveMQ Transport: tcp://localhost/127.0.0.1:61616] WireFormatNegotiator.onCommand(113) | tcp://localhost/127.0.0.1:61616 after negotiation: OpenWireFormat {version=1, cacheEnabled=true, stackTraceEnabled=true, tightEncodingEnabled=true, sizePrefixDisabled=false} DEBUG [main] TransactionContext.recover(503) | Recover: 16777216 and the exception was as follows. Exception in thread "main" java.lang.ClassCastException: [Lorg.apache.activemq.command.DataStructure; at org.apache.activemq.TransactionContext.recover(TransactionContext.java:508) at activemqtest.XATest.main(XATest.java:27) It seems to me that in case when activemq has nothing to recover as there is no transaction to recover then the code has problems and the offending line is return (XATransactionId[]) receipt.getData(); And my ide is on evaluating this line shows me receipt.getData() = org.apache.activemq.command.DataStructure [0] and it seems to me that this array of DataStructure contains nothing and it is just instantiated without any elements and the class used to instatiate is not the instance of XATransactionId, i think it might work if there is something to recover.
          Hide
          james strachan added a comment -

          Guy

          I've added your test case to subversion...

          https://svn.apache.org/repos/asf/incubator/activemq/trunk/activemq-test-atomikos/

          Unfortunately it works perfectly against trunk. I'm guessing the test case only fails if you have XA transactions to recover?

          Shoaib

          Thanks for the great diagnosis! Yeah that line of code does look suspicious. I've patched the code in trunk to avoid the ClassCastException - though I'm not too sure how to reproduce the bug yet. I wonder could you try trunk and see if it now works for you?

          Show
          james strachan added a comment - Guy I've added your test case to subversion... https://svn.apache.org/repos/asf/incubator/activemq/trunk/activemq-test-atomikos/ Unfortunately it works perfectly against trunk. I'm guessing the test case only fails if you have XA transactions to recover? Shoaib Thanks for the great diagnosis! Yeah that line of code does look suspicious. I've patched the code in trunk to avoid the ClassCastException - though I'm not too sure how to reproduce the bug yet. I wonder could you try trunk and see if it now works for you?
          Hide
          Guy Pardon added a comment -

          Hi James,

          Thanks but no, we don't have to recover anything in this test case.
          It just fails for 4.0.2 and 4.0.1. Not so for 3.1.

          Also see this on the JOMT list:

          http://mail-archive.objectweb.org/jotm/2006-11/msg00002.html

          (second half of the message). The issue also seems to arise with JOTM.

          Best,
          Guy

          Show
          Guy Pardon added a comment - Hi James, Thanks but no, we don't have to recover anything in this test case. It just fails for 4.0.2 and 4.0.1. Not so for 3.1. Also see this on the JOMT list: http://mail-archive.objectweb.org/jotm/2006-11/msg00002.html (second half of the message). The issue also seems to arise with JOTM. Best, Guy
          Hide
          Guy Pardon added a comment -

          James,

          Did you try with JDK 1.4.2? That is the one we used.

          Guy

          Show
          Guy Pardon added a comment - James, Did you try with JDK 1.4.2? That is the one we used. Guy
          Hide
          james strachan added a comment -

          FWIW I've tried the same test case against 4.0.2 as well and it works fine. I'm attaching the pom.xml file you can use in the activemq-test-atomikos directory to run the test case against 4.0.2 of ActiveMQ.

          Show
          james strachan added a comment - FWIW I've tried the same test case against 4.0.2 as well and it works fine. I'm attaching the pom.xml file you can use in the activemq-test-atomikos directory to run the test case against 4.0.2 of ActiveMQ.
          Hide
          james strachan added a comment -

          This pom.xml replaces the one in activemq-test-atomikos to run against 4.0.2 of ActiveMQ

          Show
          james strachan added a comment - This pom.xml replaces the one in activemq-test-atomikos to run against 4.0.2 of ActiveMQ
          Hide
          james strachan added a comment -

          Just to make absolutely sure, I've added the test case into the 4.0 branch too

          https://svn.apache.org/repos/asf/incubator/activemq/branches/activemq-4.0/activemq-test-atomikos/

          and the test case works fine. I wonder if these tests fail on a specific platform only? I wonder could someone try running these test cases on Windows (am an OS X / unix person myself)

          BTW I tried Java 1.4.2 with the 4.0 branch (which is basically 4.0.2)

          Show
          james strachan added a comment - Just to make absolutely sure, I've added the test case into the 4.0 branch too https://svn.apache.org/repos/asf/incubator/activemq/branches/activemq-4.0/activemq-test-atomikos/ and the test case works fine. I wonder if these tests fail on a specific platform only? I wonder could someone try running these test cases on Windows (am an OS X / unix person myself) BTW I tried Java 1.4.2 with the 4.0 branch (which is basically 4.0.2)
          Hide
          Guy Pardon added a comment -

          James,

          FYI: I am seeing this exactly on OSX/Unix myself.

          What I can do is upload the whole thing as a ZIP (if you say whereto).

          Guy

          Show
          Guy Pardon added a comment - James, FYI: I am seeing this exactly on OSX/Unix myself. What I can do is upload the whole thing as a ZIP (if you say whereto). Guy
          Hide
          Shoaib Akhtar added a comment -

          Hi James,
          It is quite amazing that you cannot reproduce the problem Guy mentioned. Anyhow i am using Sun JDK 1.5.0.9 (most latest update from Sun) on Windows XP (service pack 2) with ActiveMq version 4.0.2 (the latest released version). And the problem comes i do not use linux/unix so not sure about them but on windows it is giving the classcast exception and as i said before there seems bug with activemq code when there is NO Transaction to recover and i am sure though i did not tested that in case ther is any transaction to rceover it well might work.

          Regards,
          Shoaib

          Show
          Shoaib Akhtar added a comment - Hi James, It is quite amazing that you cannot reproduce the problem Guy mentioned. Anyhow i am using Sun JDK 1.5.0.9 (most latest update from Sun) on Windows XP (service pack 2) with ActiveMq version 4.0.2 (the latest released version). And the problem comes i do not use linux/unix so not sure about them but on windows it is giving the classcast exception and as i said before there seems bug with activemq code when there is NO Transaction to recover and i am sure though i did not tested that in case ther is any transaction to rceover it well might work. Regards, Shoaib
          Hide
          james strachan added a comment -

          Hi Guy

          Just to be sure - are you saying the bug doesn't happen for you on OSX/Unix? i.e. its a windows only bug?

          Show
          james strachan added a comment - Hi Guy Just to be sure - are you saying the bug doesn't happen for you on OSX/Unix? i.e. its a windows only bug?
          Hide
          james strachan added a comment -

          Shoaib - I wonder could you try using ActiveMQ trunk (or tomorrows nightly snapshot build of 4.2-SNAPSHOT) to see if I've fixed the bug for you on your environment? I think I've nailed the ClassCastException you're seeing - am just not yet sure of the magic incantations to reproduce it so I can know for sure its fixed

          Show
          james strachan added a comment - Shoaib - I wonder could you try using ActiveMQ trunk (or tomorrows nightly snapshot build of 4.2-SNAPSHOT) to see if I've fixed the bug for you on your environment? I think I've nailed the ClassCastException you're seeing - am just not yet sure of the magic incantations to reproduce it so I can know for sure its fixed
          Hide
          Shoaib Akhtar added a comment -

          Hi James,
          In the meanwhile the url mentioned by Guy Pardon really shows that the exception occurs only when there is no transaction to recover
          http://mail-archive.objectweb.org/jotm/2006-11/msg00002.html

          Show
          Shoaib Akhtar added a comment - Hi James, In the meanwhile the url mentioned by Guy Pardon really shows that the exception occurs only when there is no transaction to recover http://mail-archive.objectweb.org/jotm/2006-11/msg00002.html
          Hide
          james strachan added a comment -

          Hi Shoaib

          Thanks for the link. FWIW the patch Mary gives is similar to the one you suggested and the one I've applied to trunk to fix this issue. So fingers crossed its fixed.

          Show
          james strachan added a comment - Hi Shoaib Thanks for the link. FWIW the patch Mary gives is similar to the one you suggested and the one I've applied to trunk to fix this issue. So fingers crossed its fixed.
          Hide
          Shoaib Akhtar added a comment -

          Hi James and Guy,

          I ran the above test with ActiveMq 3.1 on Windows Xp service pack 2 on jdk 1.5.0.9 and as mentioned by Guy it worked perfectly well. And the line i mentioned in my previous entry (i.e. return (ActiveMQXid[]) receipt.getResult(); ) evaulated to as follows

          receipt.getResult()=org.activemq.message.ActiveMQXid[0]

          and as you can see in previosu post that for 4.0.2 it evaulated to
          receipt.getData() = org.apache.activemq.command.DataStructure[0]

          I know there has been lot of changes in 3.1 nad 4.0.2 but somehow this bug was introduced as you can see
          that ActiveMQXid[0] and .DataStructure[0] has a lot of differnce as the former can be casted to ActiveMQXid[] or
          XATransactionId[] in new version but the DataStructure[0] could not be.
          So i am sure that ActiveMq code has definetly a problem here and the URL mentioned by Guy on JOTM also support this (though i could not find those lines in code) but i guess that this problem should be resolved quickly as both atomikos and activemq are great products and form an excellent combination with each other.

          Show
          Shoaib Akhtar added a comment - Hi James and Guy, I ran the above test with ActiveMq 3.1 on Windows Xp service pack 2 on jdk 1.5.0.9 and as mentioned by Guy it worked perfectly well. And the line i mentioned in my previous entry (i.e. return (ActiveMQXid[]) receipt.getResult(); ) evaulated to as follows receipt.getResult()=org.activemq.message.ActiveMQXid [0] and as you can see in previosu post that for 4.0.2 it evaulated to receipt.getData() = org.apache.activemq.command.DataStructure [0] I know there has been lot of changes in 3.1 nad 4.0.2 but somehow this bug was introduced as you can see that ActiveMQXid [0] and .DataStructure [0] has a lot of differnce as the former can be casted to ActiveMQXid[] or XATransactionId[] in new version but the DataStructure [0] could not be. So i am sure that ActiveMq code has definetly a problem here and the URL mentioned by Guy on JOTM also support this (though i could not find those lines in code) but i guess that this problem should be resolved quickly as both atomikos and activemq are great products and form an excellent combination with each other.
          Hide
          Shoaib Akhtar added a comment -

          Hi James,
          Sorry i could not see your post before i posted my comment. If it is fixed may i ask whats the timeline for it releasing as it seems to be quite a major bug.

          Best Regards and Thanks,
          Shoaib

          Show
          Shoaib Akhtar added a comment - Hi James, Sorry i could not see your post before i posted my comment. If it is fixed may i ask whats the timeline for it releasing as it seems to be quite a major bug. Best Regards and Thanks, Shoaib
          Hide
          james strachan added a comment -

          Aha! So the reason the test case was working that I checked into trunk and 4.0 branch was due to the fact that the test was using the VM transport - which tends to avoid mashalling to and from a socket, so not causing the bug.

          Have patched the test case both in trunk and in the 4.0 branch. The one in the 4.0 branch now does indeed fail with the ClassCastException. The one in trunk passes with flying colours. So this issue is now resolved and will go out as part of the 4.2 release.

          If we cut a 4.1.x bug fix release this fix can be back ported for that too

          Show
          james strachan added a comment - Aha! So the reason the test case was working that I checked into trunk and 4.0 branch was due to the fact that the test was using the VM transport - which tends to avoid mashalling to and from a socket, so not causing the bug. Have patched the test case both in trunk and in the 4.0 branch. The one in the 4.0 branch now does indeed fail with the ClassCastException. The one in trunk passes with flying colours. So this issue is now resolved and will go out as part of the 4.2 release. If we cut a 4.1.x bug fix release this fix can be back ported for that too
          Hide
          james strachan added a comment -

          Have backported the test case and fix to 4.1 branch too if we release a new bug fix release of 4.1 before 4.2

          Show
          james strachan added a comment - Have backported the test case and fix to 4.1 branch too if we release a new bug fix release of 4.1 before 4.2
          Hide
          Shoaib Akhtar added a comment -

          Hi James,
          Thanks for the fixed bug and thanks to Guy Pardon as well for reporting this issue. Last nigh i saw the patch you applied and i think though still not able to check that it should be working but the patch code seems to be a little hack i think it can be improved and that too not in TransactionContext anyhow it is still great that this bug is fixed. Great work ActiveMq team, its is a great and extremely cool messaging system. Cheers !

          Regards,
          Shoaib Akhtar

          Show
          Shoaib Akhtar added a comment - Hi James, Thanks for the fixed bug and thanks to Guy Pardon as well for reporting this issue. Last nigh i saw the patch you applied and i think though still not able to check that it should be working but the patch code seems to be a little hack i think it can be improved and that too not in TransactionContext anyhow it is still great that this bug is fixed. Great work ActiveMq team, its is a great and extremely cool messaging system. Cheers ! Regards, Shoaib Akhtar
          Hide
          james strachan added a comment -

          updated fix versions

          Show
          james strachan added a comment - updated fix versions

            People

            • Assignee:
              Unassigned
              Reporter:
              Guy Pardon
            • Votes:
              7 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development