workflow-core
workflow-core copied to clipboard
Infinite loop when applying Decide inside ForEach with compensation
Describe the bug
I think there is a bug when using Decide
inside ForEach
along with compensation that causes an infinite loop.
I'm not sure this is a bug or just a misuse of those operators, but please check it anyway @danielgerlag. I appreciate it in advance.
To Reproduce Consider the following workflow:
public class MyWorkflow : IWorkflow
{
public string Id => "Test";
public int Version => 1;
public void Build(IWorkflowBuilder<object> builder)
{
builder
.StartWith(data => {
Console.WriteLine("Step 1");
})
.Then(data => {
Console.WriteLine("Step 2");
})
.ForEach(step => new List<int> { 1 })
.Do(then => then
.Decide(data => 1)
.Branch(1, builder.CreateBranch()
.StartWith(data => {
Console.WriteLine("Step 3");
throw new Exception();
})
.CompensateWithSequence(builder => builder.StartWith(_ => { Console.WriteLine("Compensate"); })))
);
}
}
Expected behavior The output should be
Step 1
Step 2
Step 3
Compensate
but it is
Step 1
Step 2
Step 3
Step 2
Step 3
Step 2
Step 3
Step 2
(and so on)
And by the way, thank you very much guys for this amazing tool!
@danielgerlag As it seems that you did not have the chance to check it, I've decided to dig into it by myself. So I think I've found the problem and fixed it in #1075. Please confirm that this change was required and I've done the right thing. Thanks
This problem is resolved in v3.6.0.