Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/DistributedLock.Azure/AzureBlobLeaseDistributedLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ static string ConvertToValidName(string name)
);

private async ValueTask<AzureBlobLeaseDistributedLockHandle?> TryAcquireAsync(
BlobLeaseClientWrapper leaseClient,
BlobLeaseClientWrapper leaseClient,
CancellationToken cancellationToken,
bool isRetryAfterCreate)
{
try { await leaseClient.AcquireAsync(this._options.duration, cancellationToken).ConfigureAwait(false); }
try { await leaseClient.AcquireAsync(this._options.duration, cancellationToken).ConfigureAwait(false); }
catch (RequestFailedException acquireException)
{
if (acquireException.ErrorCode == AzureErrors.LeaseAlreadyPresent) { return null; }
Expand All @@ -135,6 +135,11 @@ static string ConvertToValidName(string name)
{
// if the retry fails and we created, attempt deletion to clean things up
try { await this._blobClient.DeleteIfExistsAsync().ConfigureAwait(false); }
catch (RequestFailedException deletionException) when (deletionException.ErrorCode == AzureErrors.LeaseIdMissing)
{
// handle the race condition where we try to delete and someone else acquired it
// only the original Exception from TryAcquireAsync should be thrown
}
catch (Exception deletionException)
{
throw new AggregateException(retryException, deletionException);
Expand All @@ -160,7 +165,7 @@ internal sealed class InternalHandle : IDistributedSynchronizationHandle, LeaseM
private readonly bool _ownsBlob;
private readonly AzureBlobLeaseDistributedLock _lock;
private readonly LeaseMonitor _leaseMonitor;

public InternalHandle(BlobLeaseClientWrapper leaseClient, bool ownsBlob, AzureBlobLeaseDistributedLock @lock)
{
this._leaseClient = leaseClient;
Expand Down Expand Up @@ -193,7 +198,7 @@ public async ValueTask DisposeAsync()
{
await this._lock._blobClient.DeleteIfExistsAsync(leaseId: this._leaseClient.LeaseId).ConfigureAwait(false);
}
else
else
{
await this._leaseClient.ReleaseAsync().ConfigureAwait(false);
}
Expand Down