workflow-core icon indicating copy to clipboard operation
workflow-core copied to clipboard

Infinite loop when applying Decide inside ForEach with compensation

Open badihi opened this issue 2 years ago • 1 comments

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!

badihi avatar Jun 16 '22 18:06 badihi

@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

badihi avatar Aug 01 '22 08:08 badihi

This problem is resolved in v3.6.0.

badihi avatar Sep 01 '22 21:09 badihi