Uploaded image for project: 'JBRULES'
  1. JBRULES
  2. JBRULES-2756

fireUntilHalt is doing busy wait and consuming 100% of one CPU core

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Done
    • 5.1.0.FINAL, 5.1.1.FINAL
    • 5.2.0.M1
    • drools-core
    • None

    Description

      Analysis by Greg Barton:
      =========================

      The problem is the race condition fix introduced in rev 30163. The missedNotifyAll flag is set to true immediately which causes the busy loop.
      missedNotifyAll is initialized to false, but is immediately set to true because notifyHalt() is called in AbstractWorkingMemory.queueWorkingMemoryAction() via ReteooRuleBase.newStatefulSession(). Anyway, I'll move discussions of possible solutions over to the dev list, (crossposting now) or a JIRA if you'd prefer that.

      Here's a diff for the minimal change I think fixes the problem:

      Index: src/main/java/org/drools/common/DefaultAgenda.java
      ===================================================================
      — src/main/java/org/drools/common/DefaultAgenda.java (revision 35727)
      +++ src/main/java/org/drools/common/DefaultAgenda.java (working copy)
      @@ -1048,10 +1048,10 @@
      boolean fired = fireNextItem( agendaFilter );
      fired = fired || !((AbstractWorkingMemory) this.workingMemory).getActionQueue().isEmpty();
      this.workingMemory.executeQueuedActions();

      • if ( !fired && !missedNotifyAll.get()) {
        + if ( !fired ) {
        try
        Unknown macro: { synchronized ( this.halt ) { - this.halt.wait(); + if(!missedNotifyAll.get()) this.halt.wait(); } }

        catch ( InterruptedException e ) {
        this.halt.set( true );

      Basically, move the missedNotifyAll check immediately before the wait. This still avoids the race condition, and only causes one spurious trip through the fireUntilHalt loop on startup. I'd open a JIRA with this in it but I need to get to sleep.

      Attachments

        Activity

          People

            etirelli Edson Tirelli
            etirelli Edson Tirelli
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: