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

Hang with FireUntilHalt and updateToVersion

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • None
    • 7.55.0.Final
    • core engine
    • None
    • 2021 Week 22-24 (from May 31)
    • Undefined
    • NEW
    • NEW

    Description

      While fireUntilHalt is running in a thread and processing RHS (e.g. RHS is slow), if you call KieContainer.updateToVersion(), the updateToVersion thread will hang. This is reproducible not only in Windows.

      Created unit test PR : https://github.com/kiegroup/drools/pull/3655

      Sequence of what's happening:

      Note: [Thread-0] is the thread to run fireUntilHalt(). [Time-limited test] is the main test thread so calls updateToVersion().

      ~~~
      [Thread-0] calls fireUntilHalt(). state INACTIVE -> FIRING_UNTIL_HALT
      [Thread-0] matches the rule and fires RHS. But taking some time. In this test, Thread.sleep(200).
      [Time-limited test] calls updateToVersion().
      [Time-limited test] -> KnowledgeBaseImpl.tryLockAndDeactivate() -> KnowledgeBaseImpl.tryDeactivateAllSessions() -> DefaultAgenda$ConcurrentExecutionStateMachine.tryDeactivate() -> pauseFiringUntilHalt(). currentState == ExecutionState.FIRING_UNTIL_HALT so wasFiringUntilHalt is set to 'true'. state FIRING_UNTIL_HALT -> HALTING
      [Thread-0] exits consequence.evaluate()
      [Thread-0] calls DefaultAgenda$ConcurrentExecutionStateMachine.immediateHalt(). state HALTING -> INACTIVE
      [Time-limited test] -> DefaultAgenda$ConcurrentExecutionStateMachine.tryDeactivate(). state INACTIVE -> DEACTIVATED
      [Time-limited test] -> KieBaseUpdaterImpl.run() so actual update is processed
      [Time-limited test] -> KnowledgeBaseImpl.unlockAndActivate() -> KnowledgeBaseImpl.activateAllSessions() -> DefaultAgenda$ConcurrentExecutionStateMachine.activate() -> DefaultAgenda$ConcurrentExecutionStateMachine.immediateHalt(). state DEACTIVATED -> INACTIVE
      [Time-limited test] in DefaultAgenda$ConcurrentExecutionStateMachine.activate(), wasFiringUntilHalt is true. So agenda.fireUntilHalt() is called. https://github.com/kiegroup/drools/blob/master/drools-core/src/main/java/org/drools/core/common/DefaultAgenda.java#L1334-L1337
      [Time-limited test] DefaultAgenda.fireUntilHalt(). state INACTIVE -> FIRING_UNTIL_HALT
      [Time-limited test] -> This thread fires the rule that was add by this update.
      [Time-limited test] -> calls DefaultAgenda$RestHandler$FireUntilHaltRestHandler.handleRest()
      [Time-limited test] -> Waits at agenda.propagationList.waitOnRest(); but never be notified
      ~~~

      I guess we don't want to let [Time-limited test] run fireUntilHalt() but how to prevent?

      Attachments

        Issue Links

          Activity

            People

              mfusco@redhat.com Mario Fusco
              rhn-support-tkobayas Toshiya Kobayashi
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: