Uploaded image for project: 'ActiveMQ Classic'
  1. ActiveMQ Classic
  2. AMQ-5198

MessageConsumer and Producer are not thread safe

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 5.9.0
    • 5.10.1, 5.11.0
    • None
    • None

    Description

      We currently have an object that acts both as a consumer and as a producer over the same queue.

      Lazy initialization of the scheduler is not 100% thread safe when a consumer and a producer are created sharing the same connection.

      We encountered the following sporadic NPE when a rollback() is invoked:
      Caused by: java.lang.NullPointerException
      at org.apache.activemq.thread.Scheduler.executeAfterDelay(Scheduler.java:64)
      at org.apache.activemq.ActiveMQMessageConsumer.rollback(ActiveMQMessageConsumer.java:1278)
      at org.apache.activemq.ActiveMQMessageConsumer$5.afterRollback(ActiveMQMessageConsumer.java:1054)
      at org.apache.activemq.TransactionContext.afterRollback(TransactionContext.java:157)
      ... 11 more

      We believe that the lazy initialized getScheduler() is open for a race condition when a publish and rollback are happening concurrently.

      try

      { result = scheduler = new Scheduler("ActiveMQConnection["+info.getConnectionId().getValue()+"] Scheduler"); scheduler.start(); }

      catch(Exception e)

      { throw JMSExceptionSupport.create(e); }

      The suggested fix is to simply invoke the start within the constructor of the Scheduler class.

      Attachments

        1. ActiveMq.zip
          22 kB
          Enrico Musuruana

        Activity

          People

            Unassigned Unassigned
            Malli Enrico Musuruana
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: