Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CloudBlobContainer .Exists() will hang/timeout

Tags:

c#

blob

azure

For some reason calling .Exists(), .CreateIfNotExists() and .Create() will hang and never return. I'm not actually getting a timeout exception, I just thought people might search for that term.

Here is the specific code:

var container = _blobClient.GetContainerReference("report_dunderMifflin_details");

container.CreateIfNotExists(BlobContainerPublicAccessType.Off);

//alternatively, because I know it doesn't exist yet
//I can just call Create and it will hang too
container.Create();
like image 234
viggity Avatar asked Nov 10 '22 15:11

viggity


1 Answers

I tried creating the same container (report_dunderMifflin_details) manually through the Azure Portal, and I get an exception that says that:

Container names can contain only letters, numbers, and hyphens and must be lowercase. The name must start with a letter or a number. The name can't contain two consecutive hyphens.

Once I changed my container name from report_dunderMifflin_details to report-dundermifflin-details, it worked just fine. It is really disappointing that no exception was thrown in the Windows.AzureStorage classes.

Edit 1:

It would appear that calling Create() on a container that already exists even if the name uses the proper format will also cause the call to hand. lame.

Edit 2:

I already started writing a facade on top of the Azure SDK so that it isn't quite a complicated and implements an interface for mocking/testing purposes. I added this helper method to my facade to check for bad proposed container names.

private void CheckContainer(string containerName)
{
    var invalidNameMessage = "Container names can contain only letters, numbers, and hyphens and must be lowercase. The name must start with a letter or a number. The name can't contain two consecutive hyphens.";

    var anyInvalidChars = new Regex("[^0-9a-z-]");
    if (anyInvalidChars.IsMatch(containerName))
        throw new ArgumentException(invalidNameMessage);

    var startsWithHyphen = new Regex("$-");
    if (startsWithHyphen.IsMatch(containerName))
        throw new ArgumentException(invalidNameMessage);

    var twoHyphens = new Regex("--");
    if (twoHyphens.IsMatch(containerName))
        throw new ArgumentException(invalidNameMessage);
}
like image 90
viggity Avatar answered Nov 14 '22 23:11

viggity