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

Memory corruption using property reactivity in phreak

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 6.0.1.Final
    • None
    • None
    • None

    Description

      This issue can be reproduced with the test case pasted below. Note that if you remove the @PropertyReactive annotation from the Hero class the test becomes green.

      More in detail the problem is caused by the fact that at some point, with property reactivity on, the method RuleNetworkEvaluator.doUpdatesReorderLeftMemory at line 802 tries to remove a leftTuple from an already empty memory causing the size to drop to -1 and then the memory corruption you found this morning.

      I believe that this is in turn caused by the fact that with property reactivity some updated staged left tuples are missing (because not propagated by the AlphaNode.modifyObject method at line 148) and this prevents the correct update of the memories.

          @Test
          public void testWumpus() {
              String drl = "import org.drools.compiler.integrationtests.Misc2Test.Hero;\n" +
                           "import org.drools.compiler.integrationtests.Misc2Test.StepForwardCommand;\n" +
                           "import org.drools.compiler.integrationtests.Misc2Test.ChangeDirectionCommand;\n" +
                           "\n" +
                           "rule RotateLeft when\n" +
                           "    $h  : Hero( goingRight == true )\n" +
                           "    $dc : ChangeDirectionCommand()\n" +
                           "then\n" +
                           "    retract ( $dc );   \n" +
                           "    modify ( $h ) { setGoingRight( false ) };\n" +
                           "end\n" +
                           "\n" +
                           "rule RotateRight when\n" +
                           "    $h  : Hero( goingRight == false )\n" +
                           "    $dc : ChangeDirectionCommand()\n" +
                           "then\n" +
                           "    retract ( $dc );   \n" +
                           "    modify ( $h ) { setGoingRight( true ) };\n" +
                           "end\n" +
                           "\n" +
                           "rule StepLeft when\n" +
                           "    $h  : Hero( goingRight == false )\n" +
                           "    $sc : StepForwardCommand()\n" +
                           "then\n" +
                           "    retract ( $sc );   \n" +
                           "    modify ( $h ) { setPos( $h.getPos()-1 ) };\n" +
                           "end\n" +
                           "\n" +
                           "rule StepRight when\n" +
                           "    $h  : Hero( goingRight == true )\n" +
                           "    $sc : StepForwardCommand()\n" +
                           "then\n" +
                           "    retract ( $sc );\n" +
                           "    modify ( $h ) { setPos( $h.getPos()+1 ) };\n" +
                           "end\n";
      
              KnowledgeBuilderConfiguration kbConf = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
              KnowledgeBase kbase = loadKnowledgeBaseFromString( kbConf, drl );
      
              StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
      
              Hero hero = new Hero(1);
              ksession.insert(hero);
              ksession.fireAllRules();
      
              ksession.insert(new StepForwardCommand());
              ksession.fireAllRules();
              ksession.insert(new StepForwardCommand());
              ksession.fireAllRules();
              assertEquals(3, hero.getPos());
      
              ksession.insert(new ChangeDirectionCommand());
              ksession.fireAllRules();
              ksession.insert(new StepForwardCommand());
              ksession.fireAllRules();
              assertEquals(2, hero.getPos());
          }
      
          @PropertyReactive
          public static class Hero {
              private int pos = 1;
              private boolean goingRight = true;
      
              public Hero(int pos) {
                  this.pos = pos;
              }
      
              public int getPos() {
                  return pos;
              }
      
              public void setPos(int pos) {
                  this.pos = pos;
              }
      
              public boolean isGoingRight() {
                  return goingRight;
              }
      
              public void setGoingRight(boolean goingRight) {
                  this.goingRight = goingRight;
              }
          }
      
          public static class ChangeDirectionCommand { }
          public static class StepForwardCommand { }
      

      Attachments

        Issue Links

          Activity

            People

              mfusco@redhat.com Mario Fusco
              mfusco@redhat.com Mario Fusco
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: