Azure blob storage exception "An existing connection was forcibly closed by the remote host"
Asked Answered
R

2

6

I'm trying to use azure blob storage. I uploaded some images successfully, but all the sudden I get the error:

An existing connection was forcibly closed by the remote host

I looked into it and the exception is thrown whenever I try to check if a blob container exists.

This is my code:

BlobClient getter property: (note, I have marked sensitive data in the connection string with **)

static string connectionString = "DefaultEndpointsProtocol=https;AccountName=**;AccountKey=**;BlobEndpoint=https://**.blob.core.windows.net/;TableEndpoint=https://**.table.core.windows.net/;QueueEndpoint=https://**.queue.core.windows.net/;FileEndpoint=https://**.file.core.windows.net/";
public static CloudBlobClient BlobClient
{
            get
            {
                // Retrieve storage account from connection string.
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

                // Create the blob client.
                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
                return blobClient;
            }
}

The actual code throwing the exception:

 CloudBlobContainer container = BlobClient.GetContainerReference(containerName);
 if (!container.Exists())

To be precise, the exception occurs at the line where I check if the container exists.

I have no idea what's wrong. I am positive that the connection string is right(I copied it in).

I would REALLY appreciate if someone could tell me what the issue possibly could be.

Raji answered 25/3, 2016 at 0:55 Comment(8)
Can you see the container in the portal?Filet
@JackZeng Yes I can.Raji
@JackZeng I'm even using azure storage explorer, and from there I can upload just fine.Raji
@JackZeng Strange thing, now it works again for no apparent reason. What could have caused this? It shouldn't have anything to do with timeouts or network since the file is very small (20kb)Raji
It may be caused by network failure or server side maintenance. I can't reproduce your issue, so it's not possible to find the real reason for it.Filet
How is your subscription? Is it a student or MSDN subscription? Could it be at it's limit?Neuropsychiatry
@PedroG.Dias I am on a trial subscriptionRaji
It's a network failure which is nothing to do with your code. :)Stansberry
V
0

A best practice for scalability is to increase the .NET default connection limit to 100. By default in a client environment the default is 2. The default connection limit must be set prior to opening any connections. For this an other scalability best practice please see the Microsoft Azure Storage Performance and Scalability Checklist.

Vane answered 31/3, 2016 at 20:46 Comment(0)
T
0

It can also happen due to a timeout. In such case, you can use BlobRequestOptions to set the timeout of your choice. (I found it useful in CloudBlobContainer.ListBlobsSegmented method.)

Here is the code example for your question:

CloudBlobContainer container = blobClient.GetContainerReference(containerName);

var containerExists = container.Exists(new BlobRequestOptions() {
    ServerTimeout = TimeSpan.FromMinutes(5) 
});

if (!containerExists)
// ...
Takeover answered 20/3, 2018 at 8:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.