in src/Microsoft.Azure.WebJobs.Host.Storage/Singleton/BlobLeaseDistributedLockManager.cs [254:318]
private async Task<bool> TryCreateAsync(BlobClient blobClient, CancellationToken cancellationToken)
{
bool isContainerNotFoundException = false;
try
{
using (Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(string.Empty)))
{
await blobClient.UploadAsync(stream, cancellationToken: cancellationToken);
}
return true;
}
catch (RequestFailedException exception)
{
if (exception.Status == 404)
{
isContainerNotFoundException = true;
}
else if (exception.Status == 409 ||
exception.Status == 412)
{
// The blob already exists, or is leased by someone else
return false;
}
else
{
throw;
}
}
Debug.Assert(isContainerNotFoundException);
var container = GetParentBlobContainerClient(blobClient);
try
{
await container.CreateIfNotExistsAsync(cancellationToken: cancellationToken);
}
catch (RequestFailedException exception)
when (exception.Status == 409 && string.Compare("ContainerBeingDeleted", exception.ErrorCode) == 0)
{
throw new RequestFailedException("The host container is pending deletion and currently inaccessible.");
}
try
{
using (Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(string.Empty)))
{
await blobClient.UploadAsync(stream, cancellationToken: cancellationToken);
}
return true;
}
catch (RequestFailedException exception)
{
if (exception.Status == 409 || exception.Status == 412)
{
// The blob already exists, or is leased by someone else
return false;
}
else
{
throw;
}
}
}