tkobayas commented on PR #6298: URL: https://github.com/apache/incubator-kie-drools/pull/6298#issuecomment-2772051509
What's happening? - `SubnetworkTuple`s are created for [RightInputAdapterNode(8)] by `PhreakFromNode` using its `dataProvider`. - Segment[FromNode(7)] has 2 child segments: Segment[RightInputAdapterNode(8)], Segment[RightInputAdapterNode(13)]. So `RuleNetworkEvaluator.innerEval` creates peers for Segment[RightInputAdapterNode(13)] using the above `SubnetworkTuple` as original. The original `SubnetworkTuple`'s `peer` field refers to the created peer object. https://github.com/apache/incubator-kie-drools/blob/10.0.0/drools-core/src/main/java/org/drools/core/phreak/RuleNetworkEvaluator.java#L367 - [RightInputAdapterNode(8)] has 2 sinks : [ AccumulateNode(9) ], [ AccumulateNode(11) ]. In `RuleNetworkEvaluator.doRiaNode2` for [RightInputAdapterNode(8)], another peers are created for [ AccumulateNode(11) ] using the same original `SubnetworkTuple`s. The original `SubnetworkTuple`'s `peer` field is overwritten with the newly created peers. Now, the original/peer are not aligned with segments - R1 is fired and `update` is called - In `processPeerUpdates`, peer for [ AccumulateNode(11) ] is added to smem [RightInputAdapterNode(13)] stagedLeftTuples https://github.com/apache/incubator-kie-drools/blob/10.0.0/drools-core/src/main/java/org/drools/core/phreak/SegmentPropagator.java#L116 . This addition itself is the problem, furthermore, `smem.getStagedLeftTuples().addUpdate( peer );` adds the peers in the reverse order for stagedNext/stagePrevious (Item4->Item3->Item2->Item1), while its next/previous are (Item1->Item2->Item3->Item4). It causes the NPE later. - PhreakAccumulateNode.doNode for [ AccumulateNode(14) ] -> `RuleNetworkEvaluator.doUpdatesReorderRightMemory`. `rightTuple.next` is null -> NPE. The problem looks to me creating "peer" in 2 places (in different levels). Creating peer in `RuleNetworkEvaluator.innerEval` seems to be the main usage, while creating peer in `doRiaNode2` seems to be an exceptional case. When mixing them using the same `SubnetworkTuple` as original, the issue arises. I'm not very sure which is the right direction to fix. Some thoughts... - Creating peer in `doRiaNode2` should be separated from the peer created in `innerEval`? e.g. adding new field `riaPeer` - If `BuildUtils.areNodesCompatibleForSharing` always returns false for RightInputAdapterNode, creating peer in `doRiaNode2` wouldn't be triggered. Of course not sharing RightInputAdapterNode would have performance impact (but not so big?). https://github.com/apache/incubator-kie-drools/blob/10.0.0/drools-core/src/main/java/org/drools/core/reteoo/builder/BuildUtils.java#L186-L197 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
