azure-sdk-for-net icon indicating copy to clipboard operation
azure-sdk-for-net copied to clipboard

BlobContainerClient.CreateIfNotExistsAsync throws exception if container exists

Open Sandeep7OnShell opened this issue 2 years ago • 18 comments

Library name and version

Azure.Storage.Blobs, Version=12.10.0.0

Describe the bug

We are seeing the below error when using Container.CreateIfNotExistsAsync. Please note that the issue is intermittent.

Azure.RequestFailedException: The specified container already exists.
RequestId:8798dabf-201e-0060-0a49-60afb2000000
Time:2022-05-05T06:26:54.0405240Z
Status: 409 (The specified container already exists.)
ErrorCode: ContainerAlreadyExists

Please note that the container is never getting deleted.

Expected behavior

The Exception should not be thrown

Actual behavior

The described exception is thrown.

Reproduction Steps

Use BlobContainerClient.CreateIfNotExistsAsync, we can see the exception in some cases.

Environment

Azure App Service .Net core 3.1

Sandeep7OnShell avatar May 05 '22 06:05 Sandeep7OnShell

Thank you for your feedback. This has been routed to the support team for assistance.

ghost avatar May 05 '22 12:05 ghost

@Sandeep7OnShell Thank you for reaching out we are looking into it.

RakeshMohanMSFT avatar May 06 '22 04:05 RakeshMohanMSFT

@Sandeep7OnShell Please pardon me if I am misunderstanding your ask. But what you are raising is actually by design for client errors, you check here the ContainerAlreadyExists. BlobContainerClient.CreateIfNotExists operation creates a new container under the specified account. If the container with the same name already exists, it is not changed.

Also If a container by the same name is being deleted when Create Container is called, the server will return status code 409 (Conflict), with additional error information indicating that the container is being deleted. More information here

Note: 409 is not fatal, its just an information/indicator

RakeshMohanMSFT avatar May 06 '22 08:05 RakeshMohanMSFT

Hi @RakeshMohanMSFT By design everything is alright. The issue is when using BlobContainerClient.CreateIfNotExists, it says "Azure.RequestFailedException: The specified container already exists." whereas it should just be silent and shouldn't touch the container when it's already there.

Note: 409 is not fatal, its just an information/indicator - Application insights flags this as an error/failure. Also, further process seems to be in problem when this happens.

Sandeep7OnShell avatar May 06 '22 10:05 Sandeep7OnShell

@Sandeep7OnShell BlobContainerClient.CreateIfNotExists internally will internally query the available containers to decide to create a container or not other than that it does not impact any existing container.

As far as your application insights issue is concerned please go through this article to avoid any unnecessary noise. https://docs.microsoft.com/en-us/azure/azure-monitor/app/api-filtering-sampling#addmodify-properties-itelemetryinitializer

RakeshMohanMSFT avatar May 06 '22 15:05 RakeshMohanMSFT

BlobContainerClient.CreateIfNotExists internally will internally query the available containers to decide to create a container or not other than that it does not impact any existing container.

With the above statement, it should not throw the exception that says "Azure.RequestFailedException: The specified container already exists." We always have the container, not getting deleted ever.

Sandeep7OnShell avatar May 09 '22 04:05 Sandeep7OnShell

@Sandeep7OnShell CreateIfNotExists will not delete a container if it already exists. It will just check for a containers existence and create one if with the same name no container exists, it wont update an existing container either. Here is a REST API example

RakeshMohanMSFT avatar May 09 '22 04:05 RakeshMohanMSFT

@RakeshMohanMSFT I am not saying that it will delete the container. We have the contained, but still, we get the exception. Any thoughts on this behavior?

Sandeep7OnShell avatar May 09 '22 04:05 Sandeep7OnShell

@Sandeep7OnShell It is as designed, as the method name suggests "Create" "If" "Not" "Exists". Therefore when it when that the container with the name already exists "We have the contained(r)". It is giving a message that "Azure.RequestFailedException: The specified container already exists." and does nothing further.

RakeshMohanMSFT avatar May 09 '22 05:05 RakeshMohanMSFT

@RakeshMohanMSFT Surprised that it's giving a message via an exception and not handled gracefully.

Sandeep7OnShell avatar May 09 '22 05:05 Sandeep7OnShell

@Sandeep7OnShell I understand your concern, but as I suggested earlier you can suppress this is you application insights

As far as your application insights issue is concerned please go through this article to avoid any unnecessary noise.
https://docs.microsoft.com/en-us/azure/azure-monitor/app/api-filtering-sampling#addmodify-properties-itelemetryinitializer

RakeshMohanMSFT avatar May 09 '22 05:05 RakeshMohanMSFT

@RakeshMohanMSFT What if I am not pushing the data to AppInsights but to some other system? Doesn't sound like a solution to me.

Sandeep7OnShell avatar May 09 '22 05:05 Sandeep7OnShell

@Sandeep7OnShell Since you mentioned AppInsights earlier I suggested that.

Note: 409 is not fatal, its just an information/indicator - Application insights flags this as an error/failure. Also, further process seems to be in problem when this happens

But I understand your concern, will keep our engineering team informed to consider this requirement in future releases.

RakeshMohanMSFT avatar May 09 '22 05:05 RakeshMohanMSFT

@RakeshMohanMSFT @jsquire

Thank you for understanding the concern, please tag the necessary handles here and keep this thread posted with the latest information.

Sandeep7OnShell avatar May 09 '22 05:05 Sandeep7OnShell

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage.

Issue Details

Library name and version

Azure.Storage.Blobs, Version=12.10.0.0

Describe the bug

We are seeing the below error when using Container.CreateIfNotExistsAsync. Please note that the issue is intermittent.

Azure.RequestFailedException: The specified container already exists.
RequestId:8798dabf-201e-0060-0a49-60afb2000000
Time:2022-05-05T06:26:54.0405240Z
Status: 409 (The specified container already exists.)
ErrorCode: ContainerAlreadyExists

Please note that the container is never getting deleted.

Expected behavior

The Exception should not be thrown

Actual behavior

The described exception is thrown.

Reproduction Steps

Use BlobContainerClient.CreateIfNotExistsAsync, we can see the exception in some cases.

Environment

Azure App Service .Net core 3.1

Author: Sandeep7OnShell
Assignees: RakeshMohanMSFT
Labels:

Storage, Service Attention, Client, customer-reported, question, needs-team-attention

Milestone: -

ghost avatar May 10 '22 08:05 ghost

@xgithubtriage can you please help with the customers ask?

RakeshMohanMSFT avatar May 10 '22 09:05 RakeshMohanMSFT

Just to add my 2 cents here.

The API name CreateIfNotExists suggests that the container already existing is an expected condition for this API and as such is not "exceptional" in any way. Therefore, in my opinion, it should not be throwing an exception for an expected criteria.

Furthermore I would say that as a user my expected outcome of calling CreateIfNotExists is to ensure that at the end of the call I have a container with the details I specified. When making that call I don't really care if it already exists, I just need to make sure it does.

🤷

stap123 avatar Sep 18 '22 08:09 stap123

@Sandeep7OnShell BlobContainerClient.CreateIfNotExists internally will internally query the available containers to decide to create a container or not other than that it does not impact any existing container.

As far as your application insights issue is concerned please go through this article to avoid any unnecessary noise. docs.microsoft.com/en-us/azure/azure-monitor/app/api-filtering-sampling#addmodify-properties-itelemetryinitializer

@RakeshMohanMSFT Is there somewhere that the telemetry "Type" names are specified so we know what specific entries to exclude/update in our initializers? We wouldn't want to exclude ALL 409s for obvious reasons, just the ones from Blob storage would solve this problem. I can't find a list of the names that are used for each SDK or anything similar anywhere?

stap123 avatar Sep 18 '22 09:09 stap123

Any news to it? It stills floods the AI logs :(

EnemyArea avatar Oct 25 '22 08:10 EnemyArea

This function should not be implemented with a check for existence and then a seperate call as that can create problem if multiple instances of it are called at the same time for a given container. It should instead look like this.

           var container = client.GetBlobContainerClient(name);
            try
            {
                await container.CreateAsync(PublicAccessType.Blob);
            }
            catch(RequestFailedException ex)
            {
                if (ex.ErrorCode != "ContainerAlreadyExists")
                    throw;
            }
            return container;

cedral avatar Nov 30 '22 17:11 cedral

We are affected by the same issue. The fact that exception is thrown when container exists and logged to AppInsights enquire extra cost on our AppInsights instances. This is internal exception and should not be logged to appInsights. Suggested workaround of suppressing all 409 is not acceptable as it hides all of them leading to missing critical information for other cases when 409 is not a results of Blob.CreateIfNotExist.

@RakeshMohanMSFT , many people on this thread clearly consider it as a bug. What's required in order for the product team to treat is as a bug?

LenaVinogradov avatar Jan 27 '23 18:01 LenaVinogradov

@jsquire @RakeshMohanMSFT Please let us know when this bug will be fixed.

VoodooSV avatar Mar 06 '23 14:03 VoodooSV

Having BlobContainerClient.CreateIfNotExists raise "409 Azure.RequestFailedException: The specified container already exists." that are captured by Application Insights is not useful. It pollutes Application Insights logs. The suggestion to filter out 409s from Application Insights is not a a good solution as it will filter out all 409s.

mb30nhs avatar Jul 12 '23 13:07 mb30nhs

Hi @Sandeep7OnShell, we deeply appreciate your input into this project. Regrettably, this issue has remained unresolved for over 2 years and inactive for 30 days, leading us to the decision to close it. We've implemented this policy to maintain the relevance of our issue queue and facilitate easier navigation for new contributors. If you still believe this topic requires attention, please feel free to create a new issue, referencing this one. Thank you for your understanding and ongoing support.

github-actions[bot] avatar May 06 '24 18:05 github-actions[bot]