Drools working memory facts are not restored properly on engine reload

Description

If a Drools engine has facts in working memory when reloadConfig is called, those facts are collected in a List<Object> object, and then re-inserted into the new session.
This results in the restored objects having a different class signature than the "same" ones in the new session, since they belong to a different classloader.
When this happens, Drools queries cannot find these facts and attempting to cast them to the appropriate class using their fact handles fails with a ClassCastException.

Steps to reproduce:

  1. Define a ruleset with a declared fact class, a query that searches for facts of that class, and a rule that executes that query and performs some operation on the matching facts.

  2. Insert one of those facts into working memory

  3. Call DroolsCorrelationEngine#reloadConfig(true) (optionally by sending a reloadDaemonConfig event)

  4. Insert another fact

  5. Trigger the rule to execute the query and perform operations on matching facts

Expected behavior:

The query should find all inserted facts and perform the desired operation on them

Actual behavior:
The fact inserted before reloadConfig was called is not found by the query, but the one inserted into the current session is found.

Drools offers marshall and unmarshall methods that use protobuf for serializing and deserializing working memory safely.

Test case attached.

Acceptance / Success Criteria

None

Attachments

1
  • 11 Mar 2020, 04:27 PM

Lucidchart Diagrams

Activity

Show:

Chandra Gorantla March 25, 2020 at 3:02 AM

Thanks for the all the hints and test case. Should be resolve with PR: https://github.com/OpenNMS/opennms/pull/2935

Will Keaney March 17, 2020 at 2:13 PM

PR: https://github.com/OpenNMS/opennms/pull/2921
This should not be merged yet, see comments on the PR.

Fixed

Details

Assignee

Reporter

Components

Sprint

Affects versions

Priority

PagerDuty

Created March 11, 2020 at 4:27 PM
Updated March 12, 2025 at 9:34 PM
Resolved March 26, 2020 at 9:17 PM