From 8ece1dc9ff40049d0d2e43c89dd755fe435ffa9b Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Sun, 3 Jan 2021 19:23:59 +0100 Subject: [PATCH] Fix premature disposal of workflow execution scope --- src/core/Elsa.Core/Services/WorkflowRunner.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/Elsa.Core/Services/WorkflowRunner.cs b/src/core/Elsa.Core/Services/WorkflowRunner.cs index 45acb23aa..ba0f135a1 100644 --- a/src/core/Elsa.Core/Services/WorkflowRunner.cs +++ b/src/core/Elsa.Core/Services/WorkflowRunner.cs @@ -172,7 +172,7 @@ namespace Elsa.Services object? workflowContext = default, CancellationToken cancellationToken = default) { - var workflowExecutionScope = _serviceProvider.CreateScope(); + using var workflowExecutionScope = _serviceProvider.CreateScope(); var workflowExecutionContext = new WorkflowExecutionContext(workflowExecutionScope, workflowBlueprint, workflowInstance, input) { @@ -279,7 +279,7 @@ namespace Elsa.Services private async ValueTask RunCoreAsync(WorkflowExecutionContext workflowExecutionContext, ActivityOperation activityOperation, CancellationToken cancellationToken = default) { - using var scope = workflowExecutionContext.ServiceScope; + var scope = workflowExecutionContext.ServiceScope; var workflowBlueprint = workflowExecutionContext.WorkflowBlueprint; while (workflowExecutionContext.HasScheduledActivities) @@ -289,6 +289,7 @@ namespace Elsa.Services var activityBlueprint = workflowBlueprint.GetActivity(currentActivityId)!; var activityExecutionContext = new ActivityExecutionContext(scope, workflowExecutionContext, activityBlueprint, scheduledActivity.Input, cancellationToken); var activity = await activityExecutionContext.ActivateActivityAsync(cancellationToken); + _logger.LogDebug("Executing activity {ActivityType}: {ActivityId}", activityBlueprint.Type, currentActivityId); var result = await activityOperation(activityExecutionContext, activity); await _mediator.Publish(new ActivityExecuting(activityExecutionContext), cancellationToken); await result.ExecuteAsync(activityExecutionContext, cancellationToken);