How to ignore ETag checking and fix this error

Sarah 161 Reputation points
I read from and write to blob content in Azure blob storage. File is being changed (new content is getting appended to the file) 
at the same time while it is being downloaded. I get error in the below stream.Read() line. Which I believe is because of 
mismatch eTag values as I both read and write at the same time. 

I am actually not setting any conditional headers in the request. But you could see the error details at the bottom 
saying "Status: 412 - The condition specified using HTTP conditional header(s) is not met", I believe something is happening 
under the covers that I'm not aware of.

I tried to set conditional header ETag value as "*". Thinking it would ignore checking for matching ETag values. But this does not work.

Using Azure.Storage.Blobs package.

        originalETag = properties.ETag;
        blobOpenReadOptions = new BlobOpenReadOptions(true)
            Conditions = new BlobRequestConditions()
                IfMatch = new ETag("*")
               //IfNotMatch = originalETag

And use 

    using (var stream = await blob.OpenReadAsync(offset, segmentSize)) 
            await blob.OpenReadAsync(blobOpenReadOptions);
            stream.Position = offset;
            stream.Read(buffer, 0, buffer.Length); // ERROR in this line
            ret.Byte = buffer;

Read() error below:

    Azure.RequestFailedException: The condition specified using HTTP conditional header(s) is not met.
    Status: 412 (The condition specified using HTTP conditional header(s) is not met.)
    ErrorCode: ConditionNotMet
    <?xml version="1.0" encoding="utf-8"?><Error>
    Server: Windows-Azure-Blob/1.0,Microsoft-HTTPAPI/2.0
    x-ms-request-id: b84cc30f-501e-009f-4596-29524000000
    x-ms-client-request-id: 70f94258-163a-464c-879f-437d5ac7be7
    x-ms-version: 2021-10-04
    x-ms-error-code: ConditionNotMet
    Date: Mon, 16 Jan 2023 10:37:48 GMT
    Content-Length: 252
    Content-Type: application/xml

       at Azure.Storage.Blobs.BlobRestClient.Download(String snapshot, String versionId, Nullable
       at Azure.Storage.Blobs.Specialized.BlobBaseClient.StartDownloadAsync(HttpRange range, BlobRequestConditions conditions, DownloadTransferValidationOptions validationOptions, Int64 startOffset, Boolean async, CancellationToken cancellationToken)
       at Azure.Storage.Blobs.Specialized.BlobBaseClient.DownloadStreamingInternal(HttpRange range, BlobRequestConditions conditions, DownloadTransferValidationOptions transferValidationOverride, IProgress`1 progressHandler, String operationName, Boolean async, CancellationToken cancellationToken)
       at Azure.Storage.Blobs.Specialized.BlobBaseClient.<>c__DisplayClass97_0.<<OpenReadInternal>b__1>d.MoveNext()
    --- End of stack trace from previous location ---
       at Azure.Storage.LazyLoadingReadOnlyStream`1.DownloadInternal(Boolean async, CancellationToken cancellationToken)
       at Azure.Storage.LazyLoadingReadOnlyStream`1.ReadInternal(Byte[] buffer, Int32 offset, Int32 count, Boolean async, CancellationToken cancellationToken)
       at Azure.Core.Pipeline.TaskExtensions.EnsureCompleted[T](Task`1 task)
       at Azure.Storage.LazyLoadingReadOnlyStream`1.Read(Byte[] buffer, Int32 offset, Int32 count)
       at Project.Server.Models.ItemRepository.GetFile(String fileName, Int64 offset, Int64 blobLengthRemaining, Int64 prevContentLen) in C:\Users\Project\Server\Models\ItemRepository.cs:line 221
       at LogViewer.Server.Controllers.ItemController.GetBlobFile(String fileName, Int64 offset, Int64 blobLengthRemaining, Int64 contentLen) in C:\Users\Project\Server\Controllers\ItemController.cs:line 60
       at lambda_method60(Closure , Object )


Thank you.

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,280 questions
A set of technologies in the .NET Framework for building web applications and XML web services.
4,022 questions
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,323 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,975 questions
{count} votes

Accepted answer
  1. SaiKishor-MSFT 17,141 Reputation points

    @Sarah This is an expected behavior currently if multiple requests happen at the same time. And the only work around currently is to retry. If your requirement is that the requests happen at the same time, then the behavior is expected that you see this error. This is a bug that Microsoft will be working on fixing soon. Does that help? Please let me know! Thank you!

    0 comments No comments

0 additional answers

Sort by: Most helpful