Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harden Helix SDK against Azure Storage Blobs bug #11364

Merged
merged 1 commit into from
Oct 21, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task<Uri> UploadFileAsync(Stream stream, string blobName, Action<st
}
catch (RequestFailedException e) when (e.Status == 409)
{
if (!pageBlob.Exists())
if (!await CheckExistenceWithRetry(pageBlob, log))
{
log?.Invoke($"error : Upload of {pageBlob.Uri} failed with {e.ErrorCode}, but the blob does not exist.");
throw;
Expand All @@ -47,6 +47,31 @@ public async Task<Uri> UploadTextAsync(string text, string blobName, Action<stri
return await UploadFileAsync(new MemoryStream(bytes), blobName, log, cancellationToken);
}

private async Task<bool> CheckExistenceWithRetry(BlobClient blobClient, Action<string> log)
{
int attemptsRemaining = 5;
while (attemptsRemaining > 0)
{
try
{
bool result = await blobClient.ExistsAsync();
return result;
}
// We hit these known issues with the Azure.Storage.Blobs library:
// https://github.com/Azure/azure-storage-net/issues/1040
// https://github.com/Azure/azure-storage-net/issues/1012
// Since these are currently not addressed and this is a fallback behavior
// (checking if something's been uploaded) we'll warn and return true if the service hits this repeatedly.
catch (RequestFailedException ex) when (ex.Status == 403)
{
attemptsRemaining--;
await Task.Delay(1000);
}
}
log?.Invoke($"warning : Failed to check existence of {blobClient.Uri} but the blob likely exists, continuing.");
return true;
}

public abstract string Uri { get; }
public abstract string ReadSas { get; }
public abstract string WriteSas { get; }
Expand Down