How to ignore ETag checking and fix this error

Sarah 161 Reputation points
2023-01-18T12:50:17.69+00:00
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.
    RequestId:b84cc30f-501e-009f-4596-295240000000
    Time:2023-01-16T10:37:49.1672314Z
    Status: 412 (The condition specified using HTTP conditional header(s) is not met.)
    ErrorCode: ConditionNotMet
    
    Content:
    <?xml version="1.0" encoding="utf-8"?><Error>
    RequestId:b84cc30f-501e-009f-4596-2952400000
    Time:2023-01-16T10:37:49.1672314Z</Message></Error>
    
    Headers:
    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,430 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,175 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,393 questions
C#
C#
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.
10,260 questions
{count} votes

Accepted answer
  1. SaiKishor-MSFT 17,186 Reputation points
    2023-01-27T07:36:23.73+00:00

    @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!

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful