Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 3.3.0rc2 Stimulus api leaves orphaned entries in activity execution context when triggering events in Fork #6170

Closed
ozzyrys opened this issue Dec 2, 2024 · 1 comment · Fixed by #6213
Assignees
Labels
bug Something isn't working
Milestone

Comments

@ozzyrys
Copy link

ozzyrys commented Dec 2, 2024

Description

If there are multiple Event activities inside Fork and you trigger one of them other are left orphaned which later causes an error in WorkflowStateExtractor.ApplyActivityExecutionContextsAsync(WorkflowState state, WorkflowExecutionContext workflowExecutionContext) line 111: var parentContext = lookup[contextState.ParentContextId!];. ParentContextId is not empty here but lookup no longer contain this context.

Steps to Reproduce

  1. Detailed Steps:
    Given following workflow definition
public class TestWorkflow : WorkflowBase
{
    protected override void Build(IWorkflowBuilder builder)
    {
builder.DefinitionId = "Test__DefinitionId";
builder.Root = new Sequence
{
    Activities =
    {
        new Fork
        {
            JoinMode = ForkJoinMode.WaitAny,
            Branches =
            {
                new Sequence
                {
                    Activities =
                    {
                        new WriteLine(context => $"Retry url: {context.GenerateEventTriggerUrl("RetryEvent")}"),
                        new Event("RetryEvent"),
                        new WriteLine("Retry triggered")
                    }
                },
                new Sequence
                {
                    Activities =
                    {
                        new WriteLine(context => $"Ignore url: {context.GenerateEventTriggerUrl("IgnoreEvent")}"),
                        new Event("IgnoreEvent"),
                        new WriteLine("Ignore triggered")
                    }
                }
            }
        },
        new WriteLine(context => $"Finish url: {context.GenerateEventTriggerUrl("FinishEvent")}"),
        new Event("FinishEvent"),
        new WriteLine("End")
    }
};
}
}
  • Run worfklow instance (e.g. use endpoint /elsa/api/workflow-definitions/Test__DefinitionId/execute)
  • Trigger /events/trigger?t= for either "Retry" or "Ignore" branch (url is logged e.g. http://localhost/elsa/api/events/trigger?t=CfDJ8H-Kgs2hgapAogEBY0WJnMn3C2CpF175Qxvu1J-GD8SD66HN7xlYusEPDHxN5_uLpjKbHDMJOVbEfxn9rsEoTrAt8wkUiHCvAZyLf40P5gz91jlF9d9UEjQcU1zq85UBW5WlvG24lOaq4Y818KeVdzCf9pFGmx8eMlSbIfGo50NsJkFRhspWT5WSFOQ5P_ksnVHw0pvcDPrX2V7WGp7aCcI)
  • Try trigger "Finish" event (url is logged e.g. http://localhost/elsa/api/events/trigger?t=CfDJ8H-Kgs2hgapAogEBY0WJnMmKGIZFFNOylsIUEtMgq9j_sXY82A1mqQF0TVwbUurcITTV5AhovmWxKSIQvuoYknSMnQf_8lbXInctOCXpE68lGrUz8deDac7Zw98dLpTP03kcgxFHJ-LAXNwNkBFlFWd8dU6hQfkvBy3Ahz4l4gzr21Po4pWZbDjKLDs7L9dmikmhTLZ2VBC5MZTIG9jlpNc
  • Observer error (key not found in dictionary).
2024-12-02 16:07:23.3108 [Microsoft.AspNetCore.Diagnostics.DiagnosticsTelemetry.ReportUnhandledException:0][ERROR][0HN8ISC0LJJVI:00000003] An unhandled exception has occurred while executing the request.  System.Collections.Generic.KeyNotFoundException: The given key 'd46668af5713ed03' was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at Elsa.Workflows.WorkflowStateExtractor.ApplyActivityExecutionContextsAsync(WorkflowState state, WorkflowExecutionContext workflowExecutionContext)
   at Elsa.Workflows.WorkflowStateExtractor.ApplyAsync(WorkflowExecutionContext workflowExecutionContext, WorkflowState state)
   at Elsa.Workflows.WorkflowExecutionContext.CreateAsync(IServiceProvider serviceProvider, WorkflowGraph workflowGraph, WorkflowState workflowState, String correlationId, String parentWorkflowInstanceId, IDictionary`2 input, IDictionary`2 properties, ExecuteActivityDelegate executeDelegate, String triggerActivityId, CancellationToken cancellationToken)
   at Elsa.Workflows.WorkflowRunner.RunAsync(WorkflowGraph workflowGraph, WorkflowState workflowState, RunWorkflowOptions options, CancellationToken cancellationToken)
   at Elsa.Workflows.Runtime.LocalWorkflowClient.RunInstanceAsync(RunWorkflowInstanceRequest request, CancellationToken cancellationToken)
   at Elsa.Workflows.Runtime.StimulusSender.ResumeExistingWorkflowsAsync(String stimulusHash, StimulusMetadata metadata, CancellationToken cancellationToken)
   at Elsa.Workflows.Runtime.StimulusSender.SendAsync(String stimulusHash, StimulusMetadata metadata, CancellationToken cancellationToken)
   at Elsa.Workflows.Runtime.EventPublisher.PublishAsync(String eventName, String correlationId, String workflowInstanceId, String activityInstanceId, Object payload, CancellationToken cancellationToken)
   at Elsa.Workflows.Api.Endpoints.Events.TriggerPublic.Trigger.HandleAsync(CancellationToken cancellationToken)
   at FastEndpoints.Endpoint`2.ExecAsync(CancellationToken ct)
   at FastEndpoints.Endpoint`2.ExecAsync(CancellationToken ct)
   at Elsa.Http.Middleware.HttpWorkflowsMiddleware.InvokeAsync(HttpContext httpContext, IServiceProvider serviceProvider)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

Expected Behavior

In version 3.2.3 this is working as intended. Triggering either of the fork branches removes other branches from context and next trigger completes the workflow.

Environment

  • Elsa Package Version: 3.3.0rc2, psql store

Project with reproduction

WorkflowsElsa3.zip

@ozzyrys ozzyrys added the bug Something isn't working label Dec 2, 2024
@ozzyrys ozzyrys changed the title [BUG] 3.3.0rc2 Stimulus api leaves orphaned entries in activity execution context [BUG] 3.3.0rc2 Stimulus api leaves orphaned entries in activity execution context when triggering events in Fork Dec 2, 2024
@sfmskywalker sfmskywalker moved this to Triage in ELSA 3 Dec 12, 2024
@sfmskywalker sfmskywalker added this to the Elsa 3.3 milestone Dec 12, 2024
@sfmskywalker sfmskywalker self-assigned this Dec 14, 2024
@sfmskywalker sfmskywalker moved this from Triage to In Progress in ELSA 3 Dec 14, 2024
@sfmskywalker
Copy link
Member

Bug confirmed. Thanks for the great repro @ozzyrys 👍🏻

@sfmskywalker sfmskywalker linked a pull request Dec 14, 2024 that will close this issue
@github-project-automation github-project-automation bot moved this from In Progress to Done in ELSA 3 Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants