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

In ActiveMode, calling halt() can lead to loss of events

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • None
    • 7.74.1.Final
    • core engine
    • None
    • 2024 Week 07-09 (from Feb 12)
    • NEW
    • NEW
    • ---
    • ---

      The DRL like this:

      package org.example.drools;
      import org.example.drools.DispatchEvent;
      global java.util.List results;
      
      rule "Rule1"
      when
          $e : DispatchEvent($id : id) from entry-point "events"
      then
          results.add("received event: " + $id);
          System.out.println("received event: " + $id);
      end 

      And fire the rule in JavaCode

      EntryPoint events = session.getEntryPoint("events");
      Executors.newSingleThreadExecutor()
              .submit(() -> {
                  try {
                      System.out.println("fire until halt...");
                      session.fireUntilHalt();
                  } catch (Throwable e) {
                      e.printStackTrace(System.err);
                  }
              });
      
      sleep(1000);
      
      System.out.println("insert event aaa");
      events.insert(new DispatchEvent("aaa"));
      //sleep(100);
      
      System.out.println("insert event bbb");
      events.insert(new DispatchEvent("bbb"));
      //sleep(100);
      
      System.out.println("halt...");
      session.halt();
      sleep(1000); 
      

      Output:

      fire until halt...
      insert event aaa
      insert event bbb
      halt...
      received event: aaa
      

       

      The event "bbb" is lost.

      Add calling sleep() (whether added after inserting "aaa" or "bbb", I don't know why.), it could work fine.

      However, in real-production or in concurrent cases, it's difficult to determine how long the sleep duration should be.

              mfusco@redhat.com Mario Fusco
              gy.wang.1983 Gy Wang (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: