Uploaded image for project: 'Red Hat Decision Manager'
  1. Red Hat Decision Manager
  2. RHDM-1764

Calling fireAllRules simultaneously from multiple threads sometimes causes an exception inside MVELConsequence#evaluate.

    XMLWordPrintable

Details

    • Bug
    • Status: Verified (View Workflow)
    • Major
    • Resolution: Done
    • 7.9.0.GA, 7.11.0.GA
    • 7.12.0.GA
    • BRE
    • CR2
    • Hide
      1. Extract reproducer.
        $ unzip reproducer_mt_2a.zip
        $ cd reproducer_mt_2a
        
      2. Build and execute the rule on a machine with many cpu/cores.
        $ ./run_mvn
        

        run_mvn script builds with -DgenerateModel=NO and then runs the test (*2) 100 times. The output is written to reproducer_mt_2a_output_YYYYMMDDhhmmss.log.txt. You might be able to see exceptions like (*e1) or (*e2) several times of 100 times.

      Show
      Extract reproducer. $ unzip reproducer_mt_2a.zip $ cd reproducer_mt_2a Build and execute the rule on a machine with many cpu/cores. $ ./run_mvn run_mvn script builds with -DgenerateModel=NO and then runs the test (*2) 100 times. The output is written to reproducer_mt_2a_output_ YYYYMMDDhhmmss .log.txt . You might be able to see exceptions like (*e1) or (*e2) several times of 100 times.
    • 2021 Week 25-27 (from Jun 21)
    • ?

    Description

      When we build a rule written in MVEL dialect like (*1) with executable model disabled and run the rule using the test code like (*2), MVEL syntax error like (*e1) or (*e2) sometimes occurs though the rule normally does not cause errors. The test code simultaneously executes multiple jobs each of which creates a new KieSession, inserts objects and calls fireAllRules.

      This issue is similar to RHDM-1629. However, from the stack trace of the exception (*e1) and (*e2), it is different in the way that it does not occur inside MvelConstraint#evaluate but occurs inside MVELConsequence#evaluate (*e1-1) and (*e2-1).

      (*1)

      package com.example.reproducer
      
      dialect "mvel"
      
      rule "rule_mt_2a"
          when
              $bus : Bus( $title : "POWER PLANT" )
          then
              System.out.println("***** Action of rule_mt_2a");
              System.out.println("***** artist: " + $bus.karaoke.dvd[$title].artist);
      end
      

      (*2) Test code (In the actual code in the reproducer, java.util.concurrent.Semaphore is used for making reproducibility higher.)

          KieServices kServices = KieServices.Factory.get();
          KieContainer kContainer = kServices.getKieClasspathContainer();
      
          int THREADS = 32;
          int REQUESTS = 10000;
      
          ExecutorService pool = Executors.newFixedThreadPool(THREADS);
          List<Future<?>> fs = new ArrayList<>();
      
          System.out.println("***** start threads");
          for (int i = 0; i < REQUESTS; i++) {
              fs.add(pool.submit(new Runnable() {
                  public void run() {
                      KieSession kSession = kContainer.newKieSession("session1");
      
                      Bus bus1 = new Bus("red", 30);
                      bus1.getKaraoke().getDvd().put("POWER PLANT", new Album("POWER PLANT", "GAMMA RAY"));
                      bus1.getKaraoke().getDvd().put("Somewhere Out In Space", new Album("Somewhere Out In Space", "GAMMA RAY"));
                      kSession.insert(bus1);
      
                      try {
                          kSession.fireAllRules();
                      } catch (Exception e) {
                          e.printStackTrace();
                      }
                      
                      kSession.dispose();
                      kSession.destroy();
                  }
              }));
          }
      

      (*e1)

      Exception executing consequence for rule "rule_mt_2a" in com.example.reproducer: [Error: unable to resolve method using strict-mode: java.lang.Object.artist()]
      [Near : {... .out.println("***** artist: " + $bus.karaoke.dvd[$ ....}]
                                       ^
      [Line: 2, Column: 35]
              at org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
              at org.drools.core.common.DefaultAgenda.handleException(DefaultAgenda.java:1306)
              at org.drools.core.phreak.RuleExecutor.innerFireActivation(RuleExecutor.java:455)
              at org.drools.core.phreak.RuleExecutor.fireActivation(RuleExecutor.java:395)
              at org.drools.core.phreak.RuleExecutor.fire(RuleExecutor.java:151)
              at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:103)
              at org.drools.core.concurrent.AbstractRuleEvaluator.internalEvaluateAndFire(AbstractRuleEvaluator.java:33)
              at org.drools.core.concurrent.SequentialRuleEvaluator.evaluateAndFire(SequentialRuleEvaluator.java:43)
              at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1116)
              at org.drools.core.common.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:1063)
              at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1055)
              at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1346)
              at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1337)
              at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1321)
              at com.example.reproducer.DroolsTest$1.run(DroolsTest.java:73)
              at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
              at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
              at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
              at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
              at java.base/java.lang.Thread.run(Thread.java:834)
      Caused by: [Error: unable to resolve method using strict-mode: java.lang.Object.artist()]
      [Near : {... .out.println("***** artist: " + $bus.karaoke.dvd[$ ....}]
                                       ^
      [Line: 2, Column: 35]
              at org.mvel2.compiler.PropertyVerifier.getMethod(PropertyVerifier.java:581)
              at org.mvel2.compiler.PropertyVerifier.getBeanProperty(PropertyVerifier.java:295)
              at org.mvel2.compiler.PropertyVerifier.analyze(PropertyVerifier.java:133)
              at org.mvel2.compiler.ExpressionCompiler.verify(ExpressionCompiler.java:400)
              at org.mvel2.compiler.ExpressionCompiler._compile(ExpressionCompiler.java:259)
              at org.mvel2.util.ParseTools.subCompileExpression(ParseTools.java:2118)
              at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:969)
              at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:400)
              at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:167)
              at org.mvel2.ast.ASTNode.optimize(ASTNode.java:159)
              at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:115)
              at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
              at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
              at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
              at org.mvel2.MVEL.executeExpression(MVEL.java:945)
              at org.drools.mvel.expr.MVELConsequence.evaluate(MVELConsequence.java:108)    .......... (*e1-1)
              at org.drools.core.phreak.RuleExecutor.innerFireActivation(RuleExecutor.java:448)
              ... 17 more
      

      (*e2)

      Exception executing consequence for rule "rule_mt_2a" in com.example.reproducer: [Error: not a statement, or badly formed structure]
      [Near : {... ("***** artist: " + $bus.karaoke.dvd[$title].artis ....}]
                                       ^
      [Line: 2, Column: 47]
              at org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
              at org.drools.core.common.DefaultAgenda.handleException(DefaultAgenda.java:1306)
              at org.drools.core.phreak.RuleExecutor.innerFireActivation(RuleExecutor.java:455)
              at org.drools.core.phreak.RuleExecutor.fireActivation(RuleExecutor.java:395)
              at org.drools.core.phreak.RuleExecutor.fire(RuleExecutor.java:151)
              at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:103)
              at org.drools.core.concurrent.AbstractRuleEvaluator.internalEvaluateAndFire(AbstractRuleEvaluator.java:33)
              at org.drools.core.concurrent.SequentialRuleEvaluator.evaluateAndFire(SequentialRuleEvaluator.java:43)
              at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1116)
              at org.drools.core.common.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:1063)
              at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1055)
              at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1346)
              at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1337)
              at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1321)
              at com.example.reproducer.DroolsTest$1.run(DroolsTest.java:73)
              at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
              at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
              at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
              at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
              at java.base/java.lang.Thread.run(Thread.java:834)
      Caused by: [Error: not a statement, or badly formed structure]
      [Near : {... ("***** artist: " + $bus.karaoke.dvd[$title].artis ....}]
                                       ^
      [Line: 2, Column: 47]
              at org.mvel2.compiler.ExpressionCompiler._compile(ExpressionCompiler.java:312)
              at org.mvel2.util.ParseTools.subCompileExpression(ParseTools.java:2118)
              at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:969)
              at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:400)
              at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:167)
              at org.mvel2.ast.ASTNode.optimize(ASTNode.java:159)
              at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:115)
              at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
              at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
              at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
              at org.mvel2.MVEL.executeExpression(MVEL.java:945)
              at org.drools.mvel.expr.MVELConsequence.evaluate(MVELConsequence.java:108)    .......... (*e2-1)
              at org.drools.core.phreak.RuleExecutor.innerFireActivation(RuleExecutor.java:448)
              ... 17 more
      Caused by: java.lang.NullPointerException
              at org.mvel2.compiler.PropertyVerifier.getCollectionProperty(PropertyVerifier.java:403)
              at org.mvel2.compiler.PropertyVerifier.analyze(PropertyVerifier.java:139)
              at org.mvel2.compiler.ExpressionCompiler.verify(ExpressionCompiler.java:400)
              at org.mvel2.compiler.ExpressionCompiler._compile(ExpressionCompiler.java:259)
              ... 29 more
      

      Attachments

        Issue Links

          Activity

            People

              mfusco@redhat.com Mario Fusco
              rhn-support-myoshida Masato Yoshida
              Paolo Bizzarri Paolo Bizzarri
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: