locked
StorageException: The underlying connection was closed: An unexpected error occurred on a send. RRS feed

  • Question

  • I'm getting the following error downloading any files from blob storage. It doesn't matter what size the file is.

    [SocketException (0x2746): An existing connection was forcibly closed by the remote host]
       System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +252
    
    [IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.]
       System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +8673085
       System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count) +60
       System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) +243
       System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) +481
       System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) +8762274
       System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) +230
       System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) +645
       System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) +9
       System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) +87
       System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result) +1467
       System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size) +84
       System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size) +22
       System.Net.ConnectStream.WriteHeaders(Boolean async) +761
    
    [WebException: The underlying connection was closed: An unexpected error occurred on a send.]
       System.Net.HttpWebRequest.GetResponse() +8765848
       Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync(RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext) +4731
    
    [StorageException: The underlying connection was closed: An unexpected error occurred on a send.]
       Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync(RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext) +3332

    The code is:

    public string GetDownloadUrl(string containerName, string fileName)
     {
                // Retrieve a reference to a container. 
                CloudBlobContainer container = GetContainer(containerName);
    
                // Retrieve reference to a blob named <fileName>.
                CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName);
    
                var builder = new UriBuilder(blockBlob.Uri);
    
                builder.Query = blockBlob.GetSharedAccessSignature(new SharedAccessBlobPolicy()
                {
                    Permissions = SharedAccessBlobPermissions.Read,
                    SharedAccessExpiryTime = new DateTimeOffset(DateTime.UtcNow.AddMinutes(20))
                }).TrimStart('?');
                
                return builder.Uri.ToString().Replace("+", "%2B");
     }

    The error is happening in the method above. I think it may be in the call to GetSharedAccessSignature but I'm not certain.

    Thanks



    • Edited by ccthomas Thursday, August 6, 2015 8:32 PM
    Thursday, August 6, 2015 8:20 PM

Answers

  • Hi ccthomas,

    I have to say it must be a network issue. Please check the network configuration of your server, and try to get the built URL via browser directly to see whether it works.

    Besides, the issue can't occur in the code snippet pasted by you above, because the method GetDownloadUrl doesn't trigger any HTTP/HTTPS request. The exception should be thrown from the code to download the URL built by GetDownloadUrl.

    Best Regards,

    Zhaoxing Lu

    • Proposed as answer by Pradnya K Friday, August 14, 2015 11:18 PM
    • Marked as answer by ccthomas Saturday, August 15, 2015 1:32 AM
    Friday, August 14, 2015 1:37 AM

All replies

  • Hi,

    Do you have a timeout set for the downloading process, which might close the connection if there is no data transfer within that time?

    Regards,
    Malar.

    Friday, August 7, 2015 10:55 AM
  • Hi,

    Is this line not considered the timeout? If not, I'm not sure what you mean. Can you provide an example based on my code above.

    Thanks

    SharedAccessExpiryTime = new DateTimeOffset(DateTime.UtcNow.AddMinutes(20))
    Friday, August 7, 2015 2:11 PM
  • I think I've narrowed this problem down to one of our servers. The same code works on other servers just fine. 

    Are there any recommended approaches for troubleshooting what the issue may be. We are certain its not a network issue, looked at that already.

    Thanks

    Tuesday, August 11, 2015 2:00 PM
  • Hi ccthomas,

    I have to say it must be a network issue. Please check the network configuration of your server, and try to get the built URL via browser directly to see whether it works.

    Besides, the issue can't occur in the code snippet pasted by you above, because the method GetDownloadUrl doesn't trigger any HTTP/HTTPS request. The exception should be thrown from the code to download the URL built by GetDownloadUrl.

    Best Regards,

    Zhaoxing Lu

    • Proposed as answer by Pradnya K Friday, August 14, 2015 11:18 PM
    • Marked as answer by ccthomas Saturday, August 15, 2015 1:32 AM
    Friday, August 14, 2015 1:37 AM
  • Hi Zhaoxing,

    I think you are correct. We moved the code to another server and everything is working fine so something must have changed in our network configuration.

    Thanks

    Saturday, August 15, 2015 1:34 AM