droolsjbpm/drools — pull request #343 by danielscheu (2014-06-06 08:31:12+00:00)
Title: Infinite loop on fireAllRules after a fact modification

When I run drools with a rather huge knowledge base (> 10.000 rules) then - from time to time - I end up with drools running in an infinite loop in class LeftTupleSetsImpl. The scenario is as follows:
// Create a StateFulKnowledgeSession kSession
// Insert some facts into kSession
// kSession.fireAllRules()
// Retrieve some facts from the kSession
// Update values of the facts
// Notify drools about the updated facts (using kSession.update() and the appropriate FactHandles)
// kSession.fireAllRules() again <-- despite of identical input values, sometimes fireAllRules() succeeds - but somtimes this ends up in an infinite loop in the class LeftTupleSetsImpl
I have not much ideas about the internals of Drools but checked in the debugger where this infinite loop happens. I always end up in the while loop (which I modified in the commit). Drools never exits this loop, because current.getStagedNext() returns a reference to current, or in other words: "current == current.getStagedNext()" is true and current will never become null.
When I modify the loop like in the commit I have a drools version that does exit the loop and that does then work as expected. I am really not sure if this modification of the while loop is ok or if this should rather be an illegal state and the root error is caused elsewhere?
Unfortunately I can not reproduce this error in a smaller scenario but only with production data that I can't provide to you.
Thank you for evaluating this (possible) fix!