Uploaded image for project: 'JBoss Enterprise Application Platform'
  1. JBoss Enterprise Application Platform
  2. JBEAP-8858

Synchronization issue in ActiveMQThreadPoolExecutor

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 7.1.0.DR19
    • 7.1.0.DR11, 7.1.0.DR18
    • ActiveMQ
    • None

    Description

      During investigation of test failures in Artemis test suite I've noticed that ActiveMQThreadPoolExecutor sometimes doesn't allocate new Worker for a task even if maxPoolSize = 16 and there are only 3 tasks to execute. Instead the task is queued and it waits until some worker finishes its job.

      I think the problem is in offer method.

      @Override
      public boolean offer(Runnable runnable) {
        int poolSize = executor.getPoolSize();
      
        // If the are less threads than the configured maximum, then the tasks is
        // only queued if there are some idle threads that can run that tasks.
        // We have to add the queue size, since some tasks might just have been queued
        // but not yet taken by an idle thread.
        if (poolSize < executor.getMaximumPoolSize() && (size() + executor.getActive()) >= poolSize)
          return false;
      
        return super.offer(runnable);
      }
      

      There are 3 variables which are compared with themselves - executor.getPoolSize(), size(), executor.getActive() - without any synchronization. It may happen that the if condition is false just because some variable hasn't been updated yet.

      I've created reproducer [1] for this issue. You can run it from branch [2] using following commands.

      git clone https://github.com/dudaerich/activemq-artemis
      cd activemq-artemis
      git checkout ActiveMQThreadPoolExecutorTest
      
      mvn test -Dtest=ActiveMQThreadPoolExecutorTest -Ptests -DfailIfNoTests=false -Drat.ignoreErrors=true 2>&1 | tee log
      

      [1] https://github.com/dudaerich/activemq-artemis/blob/a0eb0ea9caaf22a9d031d480625a638a2e0f300d/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/util/ActiveMQThreadPoolExecutorTest.java
      [2] https://github.com/dudaerich/activemq-artemis/commits/ActiveMQThreadPoolExecutorTest

      Attachments

        Issue Links

          Activity

            People

              rh-ee-ataylor Andy Taylor
              eduda_jira Erich Duda (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: