Repository navigation
Different Behavior when running in Linux vs Windows #509
Description
I recently came across an issue while implementing RulesEngine in a .Net 7 project. I was able to setup my rules and they were running correctly when running on my Windows Development machine, but when deployed in a Linux docker container, they were not acting as expected.
Environment Details:
Running in WSL:
"RulesEngine" Version="5.0.1"
dotnet --version
7.0.306
cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.5 LTS (Focal Fossa)"
uname -r
5.10.16.3-microsoft-standard-WSL2
Running in Docker/EC2
"RulesEngine" Version="5.0.1"
mcr.microsoft.com/dotnet/aspnet:7.0
For the provided Rule below, in windows the Activation Rule isSuccess evaluates to false as expected, Deactivation Rule isSuccess evaluates to true.
When running in Linux, as shown below, the results are the opposite of expected.
We were able to find a work around by removing the Global Param and hard coding it into the rule. After doing that the rule evaluated correctly.
Rule Json:
[
{
"WorkflowName": "MyWorkflow",
"WorkflowsToInject": null,
"RuleExpressionType": 0,
"GlobalParams": [
{
"Name": "threshold",
"Expression": "double.Parse(\u00220.25\u0022)"
}
],
"Rules": [
{
"RuleName": "Activation",
"Properties": null,
"Operator": null,
"ErrorMessage": null,
"Enabled": true,
"RuleExpressionType": 0,
"WorkflowsToInject": null,
"Rules": null,
"LocalParams": [
{
"Name": "ruleCount",
"Expression": "int.Parse(\u002215\u0022)"
}
],
"Expression": "input1.Count \u003E= ruleCount \u0026\u0026 input1.Where(x =\u003E x.Value \u003E= threshold).Count() \u003E= ruleCount",
"Actions": null,
"SuccessEvent": null
},
{
"RuleName": "Deactivation",
"Properties": null,
"Operator": null,
"ErrorMessage": null,
"Enabled": true,
"RuleExpressionType": 0,
"WorkflowsToInject": null,
"Rules": null,
"LocalParams": [
{
"Name": "ruleCount",
"Expression": "int.Parse(\u002230\u0022)"
}
],
"Expression": "input1.Count \u003E= ruleCount \u0026\u0026 input1.OrderByDescending(o =\u003E o.ChangeDateTime).Take(ruleCount).All(a =\u003E a.Value \u003C threshold)",
"Actions": null,
"SuccessEvent": null
}
]
}
]
Evaluation result from Linux
[{
"Rule": {
"RuleName": "Activation",
"Properties": null,
"Operator": null,
"ErrorMessage": null,
"Enabled": true,
"RuleExpressionType": 0,
"WorkflowsToInject": null,
"Rules": null,
"LocalParams": [
{
"Name": "ruleCount",
"Expression": "int.Parse(\"15\")"
}
],
"Expression": "input1.Count >= ruleCount && input1.Where(x => x.Value >= threshold).Count() >= ruleCount",
"Actions": null,
"SuccessEvent": null
},
"IsSuccess": true,
"ChildResults": null,
"Inputs": {
"input1": [
{
"Value": 0.13259286,
"ChangeDateTime": "2023-07-28T19:57:07.432339Z"
},
{
"Value": 0.09435427,
"ChangeDateTime": "2023-07-28T19:58:04.536459Z"
},
{
"Value": 0.14896593,
"ChangeDateTime": "2023-07-28T19:59:08.682072Z"
},
{
"Value": 0.12852388,
"ChangeDateTime": "2023-07-28T20:00:06.78036Z"
},
{
"Value": 0.17011189,
"ChangeDateTime": "2023-07-28T20:00:54.873615Z"
},
{
"Value": 0.0532116,
"ChangeDateTime": "2023-07-28T20:02:52.04049Z"
},
{
"Value": 0.04064374,
"ChangeDateTime": "2023-07-28T20:03:54.168499Z"
},
{
"Value": 0.03748944,
"ChangeDateTime": "2023-07-28T20:03:54.194786Z"
},
{
"Value": 0.07752395,
"ChangeDateTime": "2023-07-28T20:06:32.451464Z"
},
{
"Value": 0.07294922,
"ChangeDateTime": "2023-07-28T20:07:38.691755Z"
},
{
"Value": 0.09892442,
"ChangeDateTime": "2023-07-28T20:08:37.98802Z"
},
{
"Value": 0.06370641,
"ChangeDateTime": "2023-07-28T20:05:41.358461Z"
},
{
"Value": 0.07550429,
"ChangeDateTime": "2023-07-28T20:09:48.129748Z"
},
{
"Value": 0.0653021,
"ChangeDateTime": "2023-07-28T20:10:48.274482Z"
},
{
"Value": 0.09304246,
"ChangeDateTime": "2023-07-28T20:11:49.436983Z"
},
{
"Value": 0.0797422,
"ChangeDateTime": "2023-07-28T20:12:53.609118Z"
},
{
"Value": 0.08211832,
"ChangeDateTime": "2023-07-28T20:13:52.699728Z"
},
{
"Value": 0.06955433,
"ChangeDateTime": "2023-07-28T20:15:03.843289Z"
},
{
"Value": 0.07626661,
"ChangeDateTime": "2023-07-28T20:15:03.870057Z"
},
{
"Value": 0.05033984,
"ChangeDateTime": "2023-07-28T20:16:17.032262Z"
},
{
"Value": 0.05202596,
"ChangeDateTime": "2023-07-28T20:17:20.172669Z"
},
{
"Value": 0.06861198,
"ChangeDateTime": "2023-07-28T20:18:32.303309Z"
},
{
"Value": 0.04935532,
"ChangeDateTime": "2023-07-28T20:19:33.451426Z"
},
{
"Value": 0.04073699,
"ChangeDateTime": "2023-07-28T20:20:37.737395Z"
},
{
"Value": 0.02164916,
"ChangeDateTime": "2023-07-28T20:21:38.883635Z"
},
{
"Value": 0.01334031,
"ChangeDateTime": "2023-07-28T20:22:40.053193Z"
},
{
"Value": 0.0336915,
"ChangeDateTime": "2023-07-28T20:23:44.240297Z"
},
{
"Value": 0.04870055,
"ChangeDateTime": "2023-07-28T20:26:33.584756Z"
},
{
"Value": 0.07125243,
"ChangeDateTime": "2023-07-28T20:28:11.7889Z"
},
{
"Value": 0.04904275,
"ChangeDateTime": "2023-07-28T20:24:40.346216Z"
},
{
"Value": 0.03625701,
"ChangeDateTime": "2023-07-28T20:27:20.707478Z"
},
{
"Value": 0.05703328,
"ChangeDateTime": "2023-07-28T20:28:57.876436Z"
},
{
"Value": 0.04364996,
"ChangeDateTime": "2023-07-28T20:25:43.496357Z"
},
{
"Value": 0.07558272,
"ChangeDateTime": "2023-07-28T20:30:11.023295Z"
},
{
"Value": 0.03073958,
"ChangeDateTime": "2023-07-28T20:33:00.347672Z"
},
{
"Value": 0.0341309,
"ChangeDateTime": "2023-07-28T20:33:59.790621Z"
},
{
"Value": 0.05270871,
"ChangeDateTime": "2023-07-28T20:31:15.166193Z"
},
{
"Value": 0.09138862,
"ChangeDateTime": "2023-07-28T20:32:08.259273Z"
},
{
"Value": 0.15922104,
"ChangeDateTime": "2023-07-28T20:35:12.963809Z"
},
{
"Value": 0.11383641,
"ChangeDateTime": "2023-07-28T20:36:26.120815Z"
},
{
"Value": 0.12404025,
"ChangeDateTime": "2023-07-28T20:37:37.27212Z"
},
{
"Value": 0.06010197,
"ChangeDateTime": "2023-07-28T20:38:47.409412Z"
},
{
"Value": 0.08396237,
"ChangeDateTime": "2023-07-28T20:39:37.504217Z"
},
{
"Value": 0.06731881,
"ChangeDateTime": "2023-07-28T20:40:27.588895Z"
},
{
"Value": 0.05617253,
"ChangeDateTime": "2023-07-28T20:41:33.760373Z"
},
{
"Value": 0.0585155,
"ChangeDateTime": "2023-07-28T20:42:26.847144Z"
},
{
"Value": 0.06793098,
"ChangeDateTime": "2023-07-28T20:43:36.988904Z"
},
{
"Value": 0.06879344,
"ChangeDateTime": "2023-07-28T20:44:46.133926Z"
},
{
"Value": 0.06931814,
"ChangeDateTime": "2023-07-28T20:45:50.275932Z"
},
{
"Value": 0.04802603,
"ChangeDateTime": "2023-07-28T20:46:36.367289Z"
},
{
"Value": 0.04036225,
"ChangeDateTime": "2023-07-28T20:47:27.484188Z"
},
{
"Value": 0.04968483,
"ChangeDateTime": "2023-07-28T20:48:13.582228Z"
},
{
"Value": 0.0773483,
"ChangeDateTime": "2023-07-28T19:49:16.354277Z"
},
{
"Value": 0.08710921,
"ChangeDateTime": "2023-07-28T19:48:25.253743Z"
},
{
"Value": 0.07665287,
"ChangeDateTime": "2023-07-28T19:50:25.496642Z"
},
{
"Value": 0.06121748,
"ChangeDateTime": "2023-07-28T19:51:20.644955Z"
},
{
"Value": 0.04179136,
"ChangeDateTime": "2023-07-28T19:52:26.793369Z"
},
{
"Value": 0.13522345,
"ChangeDateTime": "2023-07-28T19:54:19.051669Z"
},
{
"Value": 0.08536856,
"ChangeDateTime": "2023-07-28T19:56:04.287806Z"
},
{
"Value": 0.05041369,
"ChangeDateTime": "2023-07-28T19:53:18.901696Z"
},
{
"Value": 0.1627249,
"ChangeDateTime": "2023-07-28T19:55:13.160235Z"
},
{
"Value": 0.05,
"ChangeDateTime": "2023-07-28T19:54:03.2197Z"
},
{
"Value": 0.05,
"ChangeDateTime": "2023-07-28T19:56:00.802023Z"
},
{
"Value": 0.02792705297470093,
"ChangeDateTime": "2023-07-28T20:49:03.6825337Z"
}
],
"threshold": 0.25,
"ruleCount": 15
},
"ActionResult": {
"Output": null,
"Exception": null
},
"ExceptionMessage": ""
},{
"Rule": {
"RuleName": "Deactivation",
"Properties": null,
"Operator": null,
"ErrorMessage": null,
"Enabled": true,
"RuleExpressionType": 0,
"WorkflowsToInject": null,
"Rules": null,
"LocalParams": [
{
"Name": "ruleCount",
"Expression": "int.Parse(\"30\")"
}
],
"Expression": "input1.Count >= ruleCount && input1.OrderByDescending(o => o.ChangeDateTime).Take(ruleCount).All(a => a.Value < threshold)",
"Actions": null,
"SuccessEvent": null
},
"IsSuccess": false,
"ChildResults": null,
"Inputs": {
"input1": [
{
"Value": 0.13259286,
"ChangeDateTime": "2023-07-28T19:57:07.432339Z"
},
{
"Value": 0.09435427,
"ChangeDateTime": "2023-07-28T19:58:04.536459Z"
},
{
"Value": 0.14896593,
"ChangeDateTime": "2023-07-28T19:59:08.682072Z"
},
{
"Value": 0.12852388,
"ChangeDateTime": "2023-07-28T20:00:06.78036Z"
},
{
"Value": 0.17011189,
"ChangeDateTime": "2023-07-28T20:00:54.873615Z"
},
{
"Value": 0.0532116,
"ChangeDateTime": "2023-07-28T20:02:52.04049Z"
},
{
"Value": 0.04064374,
"ChangeDateTime": "2023-07-28T20:03:54.168499Z"
},
{
"Value": 0.03748944,
"ChangeDateTime": "2023-07-28T20:03:54.194786Z"
},
{
"Value": 0.07752395,
"ChangeDateTime": "2023-07-28T20:06:32.451464Z"
},
{
"Value": 0.07294922,
"ChangeDateTime": "2023-07-28T20:07:38.691755Z"
},
{
"Value": 0.09892442,
"ChangeDateTime": "2023-07-28T20:08:37.98802Z"
},
{
"Value": 0.06370641,
"ChangeDateTime": "2023-07-28T20:05:41.358461Z"
},
{
"Value": 0.07550429,
"ChangeDateTime": "2023-07-28T20:09:48.129748Z"
},
{
"Value": 0.0653021,
"ChangeDateTime": "2023-07-28T20:10:48.274482Z"
},
{
"Value": 0.09304246,
"ChangeDateTime": "2023-07-28T20:11:49.436983Z"
},
{
"Value": 0.0797422,
"ChangeDateTime": "2023-07-28T20:12:53.609118Z"
},
{
"Value": 0.08211832,
"ChangeDateTime": "2023-07-28T20:13:52.699728Z"
},
{
"Value": 0.06955433,
"ChangeDateTime": "2023-07-28T20:15:03.843289Z"
},
{
"Value": 0.07626661,
"ChangeDateTime": "2023-07-28T20:15:03.870057Z"
},
{
"Value": 0.05033984,
"ChangeDateTime": "2023-07-28T20:16:17.032262Z"
},
{
"Value": 0.05202596,
"ChangeDateTime": "2023-07-28T20:17:20.172669Z"
},
{
"Value": 0.06861198,
"ChangeDateTime": "2023-07-28T20:18:32.303309Z"
},
{
"Value": 0.04935532,
"ChangeDateTime": "2023-07-28T20:19:33.451426Z"
},
{
"Value": 0.04073699,
"ChangeDateTime": "2023-07-28T20:20:37.737395Z"
},
{
"Value": 0.02164916,
"ChangeDateTime": "2023-07-28T20:21:38.883635Z"
},
{
"Value": 0.01334031,
"ChangeDateTime": "2023-07-28T20:22:40.053193Z"
},
{
"Value": 0.0336915,
"ChangeDateTime": "2023-07-28T20:23:44.240297Z"
},
{
"Value": 0.04870055,
"ChangeDateTime": "2023-07-28T20:26:33.584756Z"
},
{
"Value": 0.07125243,
"ChangeDateTime": "2023-07-28T20:28:11.7889Z"
},
{
"Value": 0.04904275,
"ChangeDateTime": "2023-07-28T20:24:40.346216Z"
},
{
"Value": 0.03625701,
"ChangeDateTime": "2023-07-28T20:27:20.707478Z"
},
{
"Value": 0.05703328,
"ChangeDateTime": "2023-07-28T20:28:57.876436Z"
},
{
"Value": 0.04364996,
"ChangeDateTime": "2023-07-28T20:25:43.496357Z"
},
{
"Value": 0.07558272,
"ChangeDateTime": "2023-07-28T20:30:11.023295Z"
},
{
"Value": 0.03073958,
"ChangeDateTime": "2023-07-28T20:33:00.347672Z"
},
{
"Value": 0.0341309,
"ChangeDateTime": "2023-07-28T20:33:59.790621Z"
},
{
"Value": 0.05270871,
"ChangeDateTime": "2023-07-28T20:31:15.166193Z"
},
{
"Value": 0.09138862,
"ChangeDateTime": "2023-07-28T20:32:08.259273Z"
},
{
"Value": 0.15922104,
"ChangeDateTime": "2023-07-28T20:35:12.963809Z"
},
{
"Value": 0.11383641,
"ChangeDateTime": "2023-07-28T20:36:26.120815Z"
},
{
"Value": 0.12404025,
"ChangeDateTime": "2023-07-28T20:37:37.27212Z"
},
{
"Value": 0.06010197,
"ChangeDateTime": "2023-07-28T20:38:47.409412Z"
},
{
"Value": 0.08396237,
"ChangeDateTime": "2023-07-28T20:39:37.504217Z"
},
{
"Value": 0.06731881,
"ChangeDateTime": "2023-07-28T20:40:27.588895Z"
},
{
"Value": 0.05617253,
"ChangeDateTime": "2023-07-28T20:41:33.760373Z"
},
{
"Value": 0.0585155,
"ChangeDateTime": "2023-07-28T20:42:26.847144Z"
},
{
"Value": 0.06793098,
"ChangeDateTime": "2023-07-28T20:43:36.988904Z"
},
{
"Value": 0.06879344,
"ChangeDateTime": "2023-07-28T20:44:46.133926Z"
},
{
"Value": 0.06931814,
"ChangeDateTime": "2023-07-28T20:45:50.275932Z"
},
{
"Value": 0.04802603,
"ChangeDateTime": "2023-07-28T20:46:36.367289Z"
},
{
"Value": 0.04036225,
"ChangeDateTime": "2023-07-28T20:47:27.484188Z"
},
{
"Value": 0.04968483,
"ChangeDateTime": "2023-07-28T20:48:13.582228Z"
},
{
"Value": 0.0773483,
"ChangeDateTime": "2023-07-28T19:49:16.354277Z"
},
{
"Value": 0.08710921,
"ChangeDateTime": "2023-07-28T19:48:25.253743Z"
},
{
"Value": 0.07665287,
"ChangeDateTime": "2023-07-28T19:50:25.496642Z"
},
{
"Value": 0.06121748,
"ChangeDateTime": "2023-07-28T19:51:20.644955Z"
},
{
"Value": 0.04179136,
"ChangeDateTime": "2023-07-28T19:52:26.793369Z"
},
{
"Value": 0.13522345,
"ChangeDateTime": "2023-07-28T19:54:19.051669Z"
},
{
"Value": 0.08536856,
"ChangeDateTime": "2023-07-28T19:56:04.287806Z"
},
{
"Value": 0.05041369,
"ChangeDateTime": "2023-07-28T19:53:18.901696Z"
},
{
"Value": 0.1627249,
"ChangeDateTime": "2023-07-28T19:55:13.160235Z"
},
{
"Value": 0.05,
"ChangeDateTime": "2023-07-28T19:54:03.2197Z"
},
{
"Value": 0.05,
"ChangeDateTime": "2023-07-28T19:56:00.802023Z"
},
{
"Value": 0.02792705297470093,
"ChangeDateTime": "2023-07-28T20:49:03.6825337Z"
}
],
"threshold": 0.25,
"ruleCount": 30
},
"ActionResult": {
"Output": null,
"Exception": null
},
"ExceptionMessage": ""
}]
Activity
djl-85 commentedon Aug 2, 2023
Hi. Something similar happened to me and downgrading to version 4.0.0 works as expected. It seems something is broken from version 5.0.0.
abbasc52 commentedon Aug 2, 2023
Karissa Hanberg (@khPhoenix) can you share if you are using typed object as input or dynamic object?
khPhoenix commentedon Aug 2, 2023
Abbas Cyclewala (@abbasc52) using an anonymous type from a linq select:

abbasc52 commentedon Aug 3, 2023
Hi Karissa Hanberg (@khPhoenix) ,
I am able to reproduce your issue and there seems to be some weird behavior related to
double.Parse.If i replace
double.Parsewithfloat.Parseit works as expected.If i keep global param as string and then used
double.Parsein expression that too works.I will need to dig deeper on this, since it looks like a corner case scenario. But current workaround would be to work with float.Parse or parsing it in final expression
This is the code generated in this case scenario which looks valid to me:
khPhoenix commentedon Aug 3, 2023
Thanks for the update! I'll use one of the work arounds you listed for now :-)
khPhoenix commentedon Aug 3, 2023
Interesting the issue isn't presenting with the following workflow:
abbasc52 commentedon Aug 17, 2023
Karissa Hanberg (@khPhoenix) looks like a bug with latest version of FastExpressionCompiler. I have released v5.0.2 which fixes this.