Skip to content

Commit

Permalink
Fix for locks failing to extend in certain circumstances #97
Browse files Browse the repository at this point in the history
  • Loading branch information
samcook committed Apr 4, 2022
1 parent 3898905 commit 0d5cdf3
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions RedLockNet.SERedis/RedLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ private void ExtendLockLifetime()
catch (OperationCanceledException)
{
// unlock has been called, don't extend
logger.LogDebug($"Lock renewal cancelled: {Resource} ({LockId})");
}
}


private long GetRemainingValidityTicks(Stopwatch sw)
{
Expand Down Expand Up @@ -414,8 +414,6 @@ private RedLockInstanceSummary Extend()

private void Unlock()
{
unlockCancellationTokenSource.Cancel();

// ReSharper disable once MethodSupportsCancellation
extendUnlockSemaphore.Wait();
try
Expand All @@ -430,8 +428,6 @@ private void Unlock()

private async Task UnlockAsync()
{
unlockCancellationTokenSource.Cancel();

// ReSharper disable once MethodSupportsCancellation
await extendUnlockSemaphore.WaitAsync().ConfigureAwait(false);
try
Expand Down Expand Up @@ -629,6 +625,7 @@ protected virtual void Dispose(bool disposing)
StopKeepAliveTimer();
}

unlockCancellationTokenSource.Cancel();
Unlock();

Status = RedLockStatus.Unlocked;
Expand Down Expand Up @@ -656,6 +653,7 @@ protected virtual async ValueTask DisposeAsync(bool disposing)
StopKeepAliveTimer();
}

unlockCancellationTokenSource.Cancel();
await UnlockAsync().ConfigureAwait(false);

Status = RedLockStatus.Unlocked;
Expand Down

0 comments on commit 0d5cdf3

Please sign in to comment.