azure-sdk-for-net: Container.CreateIfNotExist throws exception if container exists

We are trying to create a container reference with the new 1.7.1 SDK but when the container exists it will throw an exception:

 //Get a reference to the container for which shared access signature will be created.  
 CloudBlobContainer container = blobClient.GetContainerReference(containerName);

 // create the container if not exists
 container.CreateIfNotExist();

This is the exception:

Microsoft.WindowsAzure.StorageClient.StorageClientException was unhandled by user code
  Message=The specified container already exists.
  Source=Microsoft.WindowsAzure.StorageClient
  StackTrace:
       at Microsoft.WindowsAzure.StorageClient.EventHelper.ProcessWebResponse(WebRequest req, IAsyncResult asyncResult, EventHandler`1 handler, Object sender) in C:\Users\deisenberg\azure-sdk-for-net\microsoft-azure-api\StorageClient\EventHelper.cs:line 84
       at Microsoft.WindowsAzure.StorageClient.CloudBlobClient.EndGetResponse(IAsyncResult asyncresult, WebRequest req) in C:\Users\deisenberg\azure-sdk-for-net\microsoft-azure-api\StorageClient\CloudBlobClient.cs:line 819
       at Microsoft.WindowsAzure.StorageClient.Tasks.WebRequestExtensions.<>c__DisplayClass1.<GetResponseAsync>b__0(IAsyncResult asyncresult) in C:\Users\deisenberg\azure-sdk-for-net\microsoft-azure-api\StorageClient\Tasks\WebRequestExtensions.cs:line 103
       at Microsoft.WindowsAzure.StorageClient.Tasks.APMTask`1.OnEnd(IAsyncResult ar) in C:\Users\deisenberg\azure-sdk-for-net\microsoft-azure-api\StorageClient\Tasks\APMTask.cs:line 162
  InnerException: System.Net.WebException
       Message=The remote server returned an error: (409) Conflict.
       Source=System
       StackTrace:
            at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
            at Microsoft.WindowsAzure.StorageClient.EventHelper.ProcessWebResponse(WebRequest req, IAsyncResult asyncResult, EventHandler`1 handler, Object sender) in C:\Users\deisenberg\azure-sdk-for-net\microsoft-azure-api\StorageClient\EventHelper.cs:line 77
       InnerException: 

About this issue

  • Original URL
  • State: closed
  • Created 12 years ago
  • Reactions: 8
  • Comments: 50 (4 by maintainers)

Commits related to this issue

Most upvoted comments

It’s ridiculous that there’s a method named CreateIfNotExists that is supposed to throw if the container already exists. – That’s what the regular Create should do. – additionally, the exception that comes back has the IsRetryable boolean set to true – even though, no matter how many retries you do, it will never succeed. 😦

2.5 years later and they still have this bug. Just wow…

Why is this closed if its still a bug?

I am also having this issue via the .NET SDK (v.8.4)

Workaround:

            // Explicitly checking for the container's existence before calling CreateIfNotExists is a workaround for a known SDK issue.
            if (!container.Exists())
            {
                container.CreateIfNotExists();
            }

Still an issue here as well, I’m accessing a container in parallel and also receive the 409 conflict response. This should not be closed.

This behavior is expected and mentioned in Azure Storage Client changelog (effective for v8.0+) . Please refer to the discussion on this issue on Azure Storage GitHub repo as well for more information.

Thanks, Elham

I can confirm this is still an issue.

I can confirm this error occurs. Please re-open.

Missed that in the email thread somehow. Thanks!

public async Task TrueCreatIfNotExistsAsync(this Container container)
{
    if (await !container.ExistsASync())
    {
        await container.CreateIfNotExistsAsync();
    }
}

😦

We would have to look at a specific request, In rare cases you can get a conflict if the container is in the process of being deleted.

CreateIfNotExists still flooding app insights with 409s… In 2022, its almost 10 years now… Ridiculous indeed.

@codecadwallader ,

To make sure everyone is aware of the details: the approach you have suggested involves an unnecessary extra call to Storage Service which is undesirable in most cases. Currently the 409 conflict error is internally handled by SDK if the container already exists and is more performant since the need for an extra head call is removed.

If based on your use-case the majority of the calls to CreateIfNotExists will be against existing containers, I would suggest moving to a single step initialization on your containers.

(Please note that previously, AppInsight would report a failure if the container was created successfully which is now corrected to 409 in case the creation did not go through.)

Thanks!

I am currently having this issue.

Agreed, this is still very much a problem. App Insights is flooded with 409’s because of this bug.

hm, this crash happened with every container we are creating new with our tool. No pending remove operation or anything else was running. I will try it again with our tool.

As joeg mentioned above, you can still get a conflict if a container is currently being deleted, because the API can return neither true given that it could not create the container nor false because the container will be deleted soon. You can especially hit this behavior if you delete a container and try to recreate it again immediately.

If you would like us to investigate a specific request, please let us know.

10 years on and still a bug. Well done chaps.

I can confirm this is still the case, as @andyblack19 reported 6 months ago:

These 409 Conflict errors are considered failed dependencies in the ‘Application Map’ in App Insights. Also in the ‘End-to-end transaction details’ screen.

And I don’t see ExistsAsAsync method in Azure.Storage.Blobs 12.1.0 …

Why can’t we have a simple way of creating containers without throwing exception or generating error logs in App Insights, without the possibility to suppress them?

Pls reopen …

Agreed. Having 2.39k entries of 409 from blob storage in App Insights is unnecessary.

Re-open please.

Umm, this is still a major problem. Flooding logs with errors during normal operations. Ridiculous indeed.

Can confirm that AppInsights logs it as error too and it’s a bit of hassle to weed it out the logs

I would like to know why this issue was closed. I’m having the same issue with calling CreateIfNotExists within multiple hangfire jobs. I’m never deleting the blob container…

Though it would be worth directing attention to this issue https://github.com/Azure/azure-sdk-for-net/issues/25626 now it’s sort of been acknowledged…

Thank you for following up. It’s counter-intuitive to me that the method is designed to usually throw exceptions, but the workaround I mentioned above has been working fine.

I have this problem when I try and connect to my private storage container from an external (not Azure based) development computer. When I run the same code on Azure it works (obviously). Just in case anyone else runs into this…

Having this issue trying to create private container.

I also don’t think that this issue should be closed, we are also getting intermittent 409 conflicts from the CreateIfNotExists call. The library seems to be checking for “ContainerAlreadyExists” in that call but the 409s are still getting thrown. It seems silly to have to check if the container exists before calling CreateIfNotExists…

@czerwinskilukasz1 please note that Azure.Blob is from the next generation of Azure SDK packages (the so called track2). This issue is about the old, track1 package.

However I completely agree this issue was closed in error. It should be reopened.

Got this message today using <PackageReference Include="WindowsAzure.Storage" Version="9.3.0" /> dotnet core 2.1

The suggested code fix works, but ruins the whole point of the method: if (!await container.ExistsAsync()) { await container.CreateIfNotExistsAsync(); }

These 409 Conflict errors are considered failed dependencies in the ‘Application Map’ in App Insights. Also in the ‘End-to-end transaction details’ screen. 👎

Got this message today using <PackageReference Include="WindowsAzure.Storage" Version="9.3.0" /> dotnet core 2.1

The suggested code fix works, but ruins the whole point of the method: if (!await container.ExistsAsync()) { await container.CreateIfNotExistsAsync(); }

In my case this “if” throws another warning : 404 The specified container does not exist. (00.1s)

Azure.Storage.Blob 12.10.0

@erezvani1529

If majority of call is against existing container (we are calling CreateIfNotExists just to make sure it’s created) should we be using

if (!container.Exists()) { container.CreateIfNotExists(); }

It would be just one head against container or should we still always call that CreateIfNotExists?

Deleted my first response as I was mistaken. You’re right that I was seeing the 409 Conflict errors in Application Insights vs. unhandled exceptions. I will add the caches as you recommend.

So is this issues solved or do you have any problems reproducing it?