It seems the method CreateIfNotExist of Azure Storage SDK isn't thread safe.
If I run several concurrent threads that are trying to save media into a storage, I get "The specified container already exists" this:
Error] Unable to upload the media from Storage: https://myurl........
TwentyTwenty.Storage.StorageException: Generic provider exception occurred ---> Microsoft.WindowsAzure.Storage.StorageException: The specified container already exists.
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteAsyncInternal[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext, CancellationToken token)
at Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.CreateIfNotExistsAsync(BlobContainerPublicAccessType accessType, BlobRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken)
at TwentyTwenty.Storage.Azure.AzureStorageProvider.SaveBlobStreamAsync(String containerName, String blobName, Stream source, BlobProperties properties, Boolean closeStream, Nullable`1 length)
--- End of inner exception stack trace ---
at TwentyTwenty.Storage.Azure.AzureStorageProvider.SaveBlobStreamAsync(String containerName, String blobName, Stream source, BlobProperties properties, Boolean closeStream, Nullable`1 length)
at........
Looking on internet (here a reference but there are tons of articles that talk about this problems) suggest to call it only in case is necessary so I used this code:
if(!await container.ExistsAsync().ConfigureAwait(false))
{
created = await container.CreateIfNotExistsAsync(security, _requestOptions, _context).ConfigureAwait(false);
}
It seems the method CreateIfNotExist of Azure Storage SDK isn't thread safe. If I run several concurrent threads that are trying to save media into a storage, I get "The specified container already exists" this:
Looking on internet (here a reference but there are tons of articles that talk about this problems) suggest to call it only in case is necessary so I used this code:
Hope it helps