2

My application reads blob content from Azure blob storage. The Blob content file is being changed by another program at the same time while it is being read. I get error in the Read() line. Which I believe is because of mismatch eTag values as file is both read and written at the same time.

How can I make my application ignore checking for ETag value (Which is disabling concurrency check). Tried as below. But same error.

    BlobRequestConditions blobRequestConditions = new BlobRequestConditions
    {
           IfMatch = new ETag("*")
           //IfMatch = ETag.All
    };

   using (var stream = await blob.OpenReadAsync(offset, sgmtSize, blobRequestConditions)) 
   {
      
        stream.Read(); // ERROR in this line
   }

Read() error below:

Azure.RequestFailedException: The condition specified using HTTP conditional header(s) is not met.
RequestId:0000000
Time:2022-05-16T10:37:49.1672314Z
Status: 412 (The condition specified using HTTP conditional header(s) is not met.)
ErrorCode: ConditionNotMet
Sarahrb
  • 407
  • 11
  • 24
  • 2
    AFAIK if the `IfMatch` is not set, no ETag check is done, so setting it to some magic value like `*` should not be needed. – Oliver Jan 18 '23 at 06:53
  • I am actually not setting any "conditional headers" in the request (As you could see the error details, I believe something is happening under the covers that I'm not aware of). Please correct me if my understanding is wrong. – Sarahrb Jan 18 '23 at 06:56
  • I retried adding more accurate code as above (for Azure.Storage.Blobs). Still get the same error at times. Would appreciate if you have any inputs. – Sarahrb Jan 19 '23 at 09:38
  • @jdweng Would appreciate if you have any input on this. – Sarahrb Jan 20 '23 at 13:15
  • have you tried to set the IfMatch to null? – Mo Haidar Jan 23 '23 at 22:40

2 Answers2

1
BlobProperties properties1 = await blob.GetPropertiesAsync();
string originalETag = properties.ETag;
bool retry = true;
while (retry)
{    

      try{ 
    
            BlobRequestConditions blobRequestConditions = new BlobRequestConditions
            {
                  IfMatch = new ETag(originalETag)
            };
        
            using (var stream = await blob.OpenReadAsync(offset, segmentSize, blobRequestConditions)) 
            retry = false;

        }
        catch(RequestFailedException ex){
               if (ex.ErrorCode == "ConditionNotMet")
                {
                     retry = true;
                }
                       
                else
                {
                    System.Diagnostics.Debug.WriteLine("Failed to Read");
                    throw;
                 }   
         }
 }
  
Sarahrb
  • 407
  • 11
  • 24
0

If you dont pass the blobRequestConditions to the method, it will disable the concurrency check

using (var stream = await blob.OpenReadAsync(offset, segmentSize)) 
Jonxag
  • 766
  • 7
  • 20
  • Hi, my initial code was without the definition of blobRequestConditions or passing it as a parameter but I got this error. Since I was getting this error, I am rite now trying blobRequestConditions to see if I can resolve this. – Sarahrb Jan 21 '23 at 10:32
  • If I am not wrong concurrency check is somehow set under the covers. Which is why this error occurs. – Sarahrb Jan 21 '23 at 10:34
  • Is possible to lock it for reading or is not possible on this scenario? – Jonxag Jan 23 '23 at 12:15
  • 1
    I got it working, please see the answer below. Thank you for trying to help. – Sarahrb Jan 23 '23 at 15:20