6 Replies Latest reply on May 26, 2006 5:19 AM by mwelss

    Exception: Failed to read payload

    mwelss

      I get this exception sometimes when the same instance of an ObjectMessage is delivered to the second or third topic subscriber and tries msg.getObject(). I am using messaging 1.0.1CR1 on jboss 4.0.4GA-Patch1 with ejb3 profile.
      Is there a workaround?

      Here is the stacktrace:


      2006-05-24 15:38:43,195 ERROR [STDERR] java.lang.RuntimeException: Failed to read payload
      2006-05-24 15:38:43,196 ERROR [STDERR] at org.jboss.messaging.core.message.MessageSupport.getPayload(MessageSupport.java:226)
      2006-05-24 15:38:43,196 ERROR [STDERR] at org.jboss.jms.message.JBossObjectMessage.getObject(JBossObjectMessage.java:137)



      P.S.
      Looking at the code, the payload seems to be serialized, but on the producer I set the delivery-mode to non-persistent, so why
      serialize anyway? It's all in one jboss, no cluster etc.


        • 1. Re: Exception: Failed to read payload
          timfox

          Can you post a test case that replicates it and I'll take a look?

          Thanks.

          • 2. Re: Exception: Failed to read payload
            mwelss

            Not sure if I can 'extract' the test case from our application...

            Can it be a concurrency issue? The consumers are all servlets, to which the messages are delivered almost 'at the same time'.
            In other words, would it help to synchronize on the message?

            Thanks!

            • 3. Re: Exception: Failed to read payload
              timfox

               

              "mwelss" wrote:

              Looking at the code, the payload seems to be serialized, but on the producer I set the delivery-mode to non-persistent, so why
              serialize anyway? It's all in one jboss, no cluster etc.


              This is required by the JMS spec.


              http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/jms/ObjectMessage.html

              ObjectMessage::setObject javadoc:
              Sets the serializable object containing this message's data. It is important to note that an ObjectMessage contains a snapshot of the object at the time setObject() is called; subsequent modifications of the object will have no effect on the ObjectMessage body.

              So we need to basically need to copy the message when it is set so if the user than changes the original object the object message is unchanged.

              • 4. Re: Exception: Failed to read payload
                timfox

                 

                "mwelss" wrote:
                Can it be a concurrency issue? The consumers are all servlets, to which the messages are delivered almost 'at the same time'.



                Possibly. Let me see if I can replicate it.

                • 5. Re: Exception: Failed to read payload
                  timfox

                  I have managed to replicate this.

                  It's a race condition due to >1 threads concurrently deserializing the message.

                  The fix seems to be trivial. So hopefully will be in the next release.

                  In the mean-time you should be able to work around by synchronizing on the underlying message as you mentioned. Although is slightly more complex since the message you have is actually a proxy.

                  You need to do something like:

                  
                  OjbectMessage m = (ObjectMessage)consumer.receive();
                  
                  MessageProxy mp = (MessageProxy)m;
                  
                  JBossMessage jbm = mp.getMessage();
                  
                  synchronized (mp.getMessage())
                  {
                  
                   Object myObject = m.getObject();
                  }
                  
                  


                  I haven't tried it but it should work.

                  Of course the above is completely non portable so you want to remove it once the fix is applied.





                  • 6. Re: Exception: Failed to read payload
                    mwelss

                    Yes, sychronizing fixes the problem!
                    Thanks a lot!