From fc96051628d02b16bf3d78884db2089d3f96e75f Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Thu, 9 Sep 2021 21:04:54 +0200 Subject: [PATCH] Remove unnecessary ambient locking code --- .../LockingWorkflowInstanceCanceller.cs | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/core/Elsa.Core/Decorators/LockingWorkflowInstanceCanceller.cs b/src/core/Elsa.Core/Decorators/LockingWorkflowInstanceCanceller.cs index 518e2b218..b8dd22cfc 100644 --- a/src/core/Elsa.Core/Decorators/LockingWorkflowInstanceCanceller.cs +++ b/src/core/Elsa.Core/Decorators/LockingWorkflowInstanceCanceller.cs @@ -3,7 +3,6 @@ using System.Threading.Tasks; using Elsa.Exceptions; using Elsa.Options; using Elsa.Services; -using Elsa.Services.Models; namespace Elsa.Decorators { @@ -23,23 +22,12 @@ namespace Elsa.Decorators public async Task CancelAsync(string workflowInstanceId, CancellationToken cancellationToken = default) { var workflowInstanceLockKey = $"workflow-instance:{workflowInstanceId}"; - var currentWorkflowInstanceLockHandle = AmbientLockContext.GetCurrentWorkflowInstanceLock(workflowInstanceId); - var workflowInstanceLockHandle = currentWorkflowInstanceLockHandle ?? await _distributedLockProvider.AcquireLockAsync(workflowInstanceLockKey, _elsaOptions.DistributedLockTimeout, cancellationToken); + await using var workflowInstanceLockHandle = await _distributedLockProvider.AcquireLockAsync(workflowInstanceLockKey, _elsaOptions.DistributedLockTimeout, cancellationToken); if (workflowInstanceLockHandle == null) throw new LockAcquisitionException("Could not acquire a lock within the configured amount of time"); - try - { - AmbientLockContext.SetCurrentWorkflowInstanceLock(workflowInstanceId, workflowInstanceLockHandle); - - return await _workflowInstanceCanceller.CancelAsync(workflowInstanceId, cancellationToken); - } - finally - { - AmbientLockContext.DeleteCurrentWorkflowInstanceLock(workflowInstanceId); - await workflowInstanceLockHandle.DisposeAsync(); - } + return await _workflowInstanceCanceller.CancelAsync(workflowInstanceId, cancellationToken); } } } \ No newline at end of file