elsa-workflows / elsa-core

A .NET workflows library
https://v3.elsaworkflows.io/
MIT License
6.25k stars 1.14k forks source link

[BUG]fail: Microsoft.AspNetCore.Server.Kestrel[13] Connection id "0HN5CTU3SMF6S", Request id "0HN5CTU3SMF6S:00000003": An unhandled exception was thrown by the application. #5843

Open captaris opened 1 month ago

captaris commented 1 month ago

System.Exception: Lost an owner context at Elsa.Workflows.Services.WorkflowStateExtractor.ExtractCompletionCallbacks(WorkflowState state, WorkflowExecutionContext workflowExecutionContext) at Elsa.Workflows.Services.WorkflowStateExtractor.Extract(WorkflowExecutionContext workflowExecutionContext) at Elsa.Workflows.Services.WorkflowRunner.RunAsync(WorkflowExecutionContext workflowExecutionContext) at Elsa.Workflows.Services.WorkflowRunner.RunAsync(WorkflowGraph workflowGraph, WorkflowState workflowState, RunWorkflowOptions options, CancellationToken cancellationToken) at Elsa.Workflows.Runtime.Services.WorkflowHost.ResumeWorkflowAsync(ResumeWorkflowHostParams params, CancellationToken cancellationToken) at Elsa.Workflows.Runtime.Services.DefaultWorkflowRuntime.ResumeWorkflowAsync(String workflowInstanceId, ResumeWorkflowRuntimeParams options) at Elsa.Workflows.Runtime.Services.DefaultWorkflowRuntime.ResumeWorkflowAsync(String workflowInstanceId, ResumeWorkflowRuntimeParams options) at Elsa.Workflows.Runtime.Services.DefaultWorkflowRuntime.ResumeWorkflowsAsync(IEnumerable1 bookmarks, ResumeWorkflowRuntimeParams runtimeParams) at Elsa.Workflows.Runtime.Services.DefaultWorkflowRuntime.ResumeWorkflowsAsync(String activityTypeName, Object bookmarkPayload, TriggerWorkflowsOptions options) at Elsa.Workflows.Runtime.Services.DefaultWorkflowInbox.ResumeWorkflowsSynchronouslyAsync(WorkflowInboxMessage message, CancellationToken cancellationToken) at Elsa.Workflows.Runtime.Services.DefaultWorkflowInbox.BroadcastAsync(WorkflowInboxMessage message, BroadcastWorkflowInboxMessageOptions options, CancellationToken cancellationToken) at Elsa.Workflows.Runtime.Handlers.ReadWorkflowInboxMessage.HandleAsync(WorkflowInboxMessageReceived notification, CancellationToken cancellationToken) at Elsa.Mediator.PublishingStrategies.SequentialProcessingStrategy.PublishAsync(NotificationStrategyContext context) at Elsa.Mediator.Middleware.Notification.Components.NotificationHandlerInvokerMiddleware.InvokeAsync(NotificationContext context) at Elsa.Mediator.Middleware.Notification.NotificationPipeline.ExecuteAsync(NotificationContext context) at Elsa.Mediator.Services.DefaultMediator.SendAsync(INotification notification, IEventPublishingStrategy strategy, CancellationToken cancellationToken) at Elsa.Workflows.Runtime.Services.DefaultWorkflowInbox.SubmitAsync(NewWorkflowInboxMessage newMessage, WorkflowInboxMessageDeliveryParams params, CancellationToken cancellationToken) at Elsa.Workflows.Runtime.Services.EventPublisher.PublishInternalAsync(String eventName, Boolean dispatchAsynchronously, String correlationId, String workflowInstanceId, String activityInstanceId, Object payload, CancellationToken cancellationToken) at Elsa.Workflows.Runtime.Services.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.Endpoint2.ExecAsync(CancellationToken ct) at FastEndpoints.Endpoint2.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) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context) at Microsoft.WebTools.BrowserLink.Net.BrowserLinkMiddleware.InvokeAsync(HttpContext context) at Microsoft.AspNetCore.Watch.BrowserRefresh.BrowserRefreshMiddleware.InvokeAsync(HttpContext context) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication1 application)

sfmskywalker commented 1 month ago

Can you provide detailed steps to reproduce this and or a sample project? Which version of Elsa are you seeing this?

captaris commented 1 month ago

Teacher: Hello The steps to reproduce the error are as follows:

  1. Elsa version is 3.1.3
  2. The example project is: samples/aspnet/Elsa Samples.AspNet.DocumentApproval
  3. When the first step is executed on the browser URL, it is successful: Jack approves URL: https://localhost:5001/elsa/api/events/trigger?t=CfDJ8Amm1KhNgo1IjZyyiHXpQiBi1uTcdREnJre638i2_dOytsq9JzflpEbYTx1QJdLdRtesmOqY8vjGrvQ6PF1 -Xgxhe7tg5h89CnUBhudMVxnmerwYjrvnA8o0bN4LETJNy69Eew7kAKIgUP8Hr-jbjxXHrdU-HOh6SWK09l2FLCdbh9E_XgQnQkfPiSQMLb1soTtxczWGBx7yVUgVseN3HuA
  4. The second step is to encounter an error when executing the URL in the browser: Lucy approves URL: https://localhost:5001/elsa/api/events/trigger?t=CfDJ8Amm1KhNgo1IjZyyiHXpQiBVUjPu4BFx7sV9lTIYHV443npo0wY1QtnHoxTnbYRLat_sTin4nYnn1sJxb_YnDXSeCJwRAQObhWXXZd0OQQF8N1QCYweXJiq -vvs3qcNVMrK9kx7Xxy01kWvoviT08d5jr3zz-kjbj7CvWBi7ICO9cplSKgsuIRa1x7MmxiZYxY1T95REO4eOOOGsXKe5avk
  5. When the first person performs approval or rejection in the browser URL, it is successful, but an error occurs when the second person performs approval or rejection in the browser
ciaranodonnell commented 1 month ago

I also get this issue on my custom activities. They were working on an older version of Elsa (I think 3.1). I updated today and they aren't working now. I think the problem is related to when my workflow is resuming from a bookmark, it removes the bookmark, which causes it to immediately remove the activities related to the bookmark, which is the activity thats resuming. So when it tries to find the one to resume its already been removed.

This is a guess based on what I see in the logs and the code I was able to step through. I dont fully understand the life cycle of bookmarks and running from code its not so easy to unwind the pull of the new code to compare