Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-4447

thread safety issue with Exchange.getUnitOfWork()

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.8.1
    • 2.8.2, 2.9.0
    • camel-core
    • None
    • JDK 1.6.0_20 on Linux x86_64

    • Unknown

    Description

      I'm having a somewhat rare issue with NullPointerExceptions in a multithreaded route. It seems that there is a race condition between one thread operating on the UnitOfWork and another removing it. I have gotten the following stacktraces so far:

      ERROR [Camel0 - Resequencer Delivery] o.a.c.p.StreamResequencer - Caused by: [java.lang.NullPointerException - null]
      java.lang.NullPointerException: null
      	at org.apache.camel.processor.DefaultChannel$1.done(DefaultChannel.java:309) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:349) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:209) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.processor.DefaultChannel.process(DefaultChannel.java:305) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:78) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.processor.Pipeline.process(Pipeline.java:116) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.processor.Pipeline.process(Pipeline.java:79) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:104) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.processor.Pipeline.process(Pipeline.java:59) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.processor.StreamResequencer.sendElement(StreamResequencer.java:165) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.processor.StreamResequencer.sendElement(StreamResequencer.java:61) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.processor.resequencer.ResequencerEngine.deliverNext(ResequencerEngine.java:254) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.processor.resequencer.ResequencerEngine.deliver(ResequencerEngine.java:218) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.processor.StreamResequencer$Delivery.run(StreamResequencer.java:212) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      

      And:

      ERROR [Camel0 - Resequencer Delivery] o.a.c.p.StreamResequencer - Caused by: [java.lang.NullPointerException - null]
      java.lang.NullPointerException: null
      	at org.apache.camel.impl.DefaultExchange.isTransacted(DefaultExchange.java:331) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:57) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.processor.Pipeline.process(Pipeline.java:116) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.processor.Pipeline.process(Pipeline.java:79) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:104) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.processor.Pipeline.process(Pipeline.java:59) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.processor.StreamResequencer.sendElement(StreamResequencer.java:165) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.processor.StreamResequencer.sendElement(StreamResequencer.java:61) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.processor.resequencer.ResequencerEngine.deliverNext(ResequencerEngine.java:254) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.processor.resequencer.ResequencerEngine.deliver(ResequencerEngine.java:218) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      	at org.apache.camel.processor.StreamResequencer$Delivery.run(StreamResequencer.java:212) ~[camel-core-2.8.1-SNAPSHOT.jar:2.8.1-SNAPSHOT]
      

      Looking at the source, both NullPointerExceptions were thrown by code like:

      return getUnitOfWork() != null && getUnitOfWork().isTransacted();
      

      Oddly, I've only seen this happen soon after startup and only once per run.

      The actual route is company confidential, but it's basically:

      JMS -> Stream Resequencer -> Bean

      Attachments

        1. CAMEL-4447.patch
          3 kB
          Claus Ibsen

        Activity

          People

            davsclaus Claus Ibsen
            dgtombs David Tombs
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: