[BUG] Azure.Storage.Blobs#CreateIfNotExistsAsync throws exception if the BLOB container already exists

See original GitHub issue

Describe the bug The method Azure.Storage.Blobs.CreateIfNotExistsAsync() throws an exception with:

  • Status: 409 (The specified blob already exists.)
  • ErrorCode: BlobAlreadyExists However, it is suppost to do nothing if the BLOB container already exists.

Expected behavior Nothing. Therer should just be no change.

Actual behavior (include Exception or Stack Trace) An Exception is thrown

  Exception:
    Azure.RequestFailedException: The specified blob already exists.
    RequestId:xxx
    Time:2021-01-15T14:09:55.1569279Z
    Status: 409 (The specified blob already exists.)
    ErrorCode: BlobAlreadyExists
    
    Headers:
    x-ms-request-id: xxx
    x-ms-client-request-id: xxx
    x-ms-version: 2020-04-08
    x-ms-error-code: BlobAlreadyExists
    Content-Length: 220
    Content-Type: application/xml
    Date: Fri, 15 Jan 2021 14:09:54 GMT
    Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
    
  Stack Trace: 
    BlockBlob.UploadAsync_CreateResponse(ClientDiagnostics clientDiagnostics, Response response)
    <UploadAsync>d__0.MoveNext()
    --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
    ExceptionDispatchInfo.Throw()
    TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    ValueTask`1.get_Result()
    <UploadInternal>d__27.MoveNext()
    --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
    ExceptionDispatchInfo.Throw()
    TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    <<GetPartitionedUploaderBehaviors>b__0>d.MoveNext()
    --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
    ExceptionDispatchInfo.Throw()
    TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    <UploadInternal>d__19.MoveNext()
    --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
    ExceptionDispatchInfo.Throw()
    TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    <StagedUploadInternal>d__31.MoveNext()
    --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
    ExceptionDispatchInfo.Throw()
    TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    TaskAwaiter`1.GetResult()
    <UploadFileAsync>d__5.MoveNext() line 62
    --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
    ExceptionDispatchInfo.Throw()
    TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    TaskAwaiter.GetResult()
    <UploadExistingFile_NoOverwrite_Test>d__2.MoveNext() line 30
    --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde ---
    ExceptionDispatchInfo.Throw()
    TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    ThreadOperations.ExecuteWithAbortSafety(Action action)

To Reproduce Steps to reproduce the behavior (include a code snippet, screenshot, or any additional information that might help us reproduce the issue)

var client = new BlobContainerClient("my connection string", "any unique container name which does not yet exists");
await client.CreateIfNotExistsAsync(); // Creates the BLOB client - no Exception
await client.CreateIfNotExistsAsync(); // Throws the exception

Environment:

  • Name and version of the Library package used: Azure.Storage.Blobs Version=12.8.0.0
  • Hosting platform or OS and .NET runtime version: .NET Framework 4.6.1
  • IDE and version : Microsoft Visual Studio Professional 2019 Version 16.8.4

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
renaudrenaud85commented, Apr 11, 2022

Same problem here. blobContainerClient.ExistsAsync() throws a RequestFailedException if it does not exist instead of just returning false, CreateIfNotExistsAsync() throws an exception if it exists. Very annoying because I don’t know how to keep those exceptions away from AppInsights.

0reactions
amnguyecommented, Jun 10, 2022

This issue regarding the exceptions being logged to Application Insights is unrelated to the original issue. The original poster was not using Application Insights. They were simply noting an exception was still being thrown from their code (not Application Insights) and they saw it, when they expected it not to.

Please do not create unnecessary noise for the original poster of the issue.

I found the related issue you’re looking for that you can take your concerns to

https://github.com/Azure/azure-sdk-for-net/issues/18592

Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Container.CreateIfNotExist throws exception if ...
Microsoft.WindowsAzure.StorageClient.StorageClientException was unhandled by user code Message=The specified container already exists. Source=Microsoft.
Read more >
Azure Blob Storage throws exception when creating a new ...
always creates the container in Azure and then throws an exception saying it already exists. 'The specified container already exists. I verify ...
Read more >
Fails to mount an Azure Blob storage container
Solution: Ensure the Blob container exists. To resolve this issue, make sure that the Blob container that's associated with the PV/PVC exists.
Read more >
BlobContainerClient.CreateIfNotExists Method
BlobContainer specifies full public read access for container and blob data. Clients can enumerate blobs within the container via anonymous request, but cannot ......
Read more >
Azure Blob Storage error codes
Error code HTTP status code User message BlobAlreadyExists Conflict (409) The specified blob already exists. BlobNotFound Not Found (404) The specified blob does not exist. ContainerAlreadyExists...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found