Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-1000

Race condition occured when executing Drools

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 6.4.0.Beta2
    • 6.2.0.Final
    • core engine
    • None
    • Hide

      We tried on reproducing the issue but with no luck

      Show
      We tried on reproducing the issue but with no luck
    • NEW
    • NEW

    Description

      We encountered soft timeout on threads executing Drools in our production environment.
      Below is the trimmed thread dump:

      "CacheWorker:2" id=988 State:RUNNABLE
      at java.util.HashMap.getEntry(HashMap.java:446)
      at java.util.HashMap.containsKey(HashMap.java:434)
      at java.util.HashSet.contains(HashSet.java:201)
      at org.drools.core.impl.KnowledgeBaseImpl.addEventListener(KnowledgeBaseImpl.java:252)
      at org.jbpm.process.instance.ProcessRuntimeImpl.initProcessEventListeners(ProcessRuntimeImpl.java:303)
      at org.jbpm.process.instance.ProcessRuntimeImpl.<init>(ProcessRuntimeImpl.java:115)
      at org.jbpm.process.instance.ProcessRuntimeFactoryServiceImpl.newProcessRuntime(ProcessRuntimeFactoryServiceImpl.java:10)
      at org.jbpm.process.instance.ProcessRuntimeFactoryServiceImpl.newProcessRuntime(ProcessRuntimeFactoryServiceImpl.java:7)
      at org.drools.core.runtime.process.ProcessRuntimeFactory.newProcessRuntime(ProcessRuntimeFactory.java:16)
      at org.drools.core.impl.StatefulKnowledgeSessionImpl.createProcessRuntime(StatefulKnowledgeSessionImpl.java:757)
      at org.drools.core.impl.StatefulKnowledgeSessionImpl.<init>(StatefulKnowledgeSessionImpl.java:393)
      at org.drools.core.impl.StatefulKnowledgeSessionImpl.<init>(StatefulKnowledgeSessionImpl.java:286)
      at org.drools.core.common.PhreakWorkingMemoryFactory.createWorkingMemory(PhreakWorkingMemoryFactory.java:21)
      at org.drools.core.impl.StatelessKnowledgeSessionImpl.newWorkingMemory(StatelessKnowledgeSessionImpl.java:127)
      at org.drools.core.impl.StatelessKnowledgeSessionImpl.execute(StatelessKnowledgeSessionImpl.java:302)

      Analysis on the Drools code reveals a possible thread safety issue. A single instance of KnowledgeBaseImpl is shared amongst multiple kSessions but inside KnowledgeBaseImpl, it contains a HashSet storing the listeners:

      public final Set<KieBaseEventListener> kieBaseListeners = new HashSet<KieBaseEventListener>();

      From the thread dump, it hanged at addEventListener method:

      public void addEventListener(KieBaseEventListener listener) {
      if (!kieBaseListeners.contains(listener))

      { eventSupport.addEventListener(listener); kieBaseListeners.add(listener); }

      }

      When 2 threads try to put into a hashmap at the same time and both trigger the map to be resized there is a small chance of created a corrupt internal data structure which results in infinite loops. There are a bunch of references on the net for this, here is one example:

      http://stackoverflow.com/questions/13695832/explain-the-timing-causing-hashmap-put-to-execute-an-infinite-loop.

      Our system heavily rely on Drools and we have high volume everyday, we really need help from Drools dev team and much appreciate if you can provide a patch for us. Thanks in advance.

      Attachments

        Activity

          People

            mfusco@redhat.com Mario Fusco
            thomashlleung Thomas Leung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: