The underlying connection was closed: An unexpected error occurred on a receive

Nov 25, 2008 at 10:18 PM
Edited Nov 27, 2008 at 9:11 PM
Hi,

I dragged and dropped an 90 MB directory (33 files) into the Package Editor and i changed the zip file name and it crashed during the transfer with the following staack trace

System.ServiceModel.CommunicationException: An error occurred while receiving the HTTP response to http://files.company.ca/Transfer/wcfTransferService.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   --- End of inner exception stack trace ---

Server stack trace:
   at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Send(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at ITransferService.Upload(RemoteFileDescriptor request)
   at TransferServiceClient.ITransferService.Upload(RemoteFileDescriptor request)
   at TransferServiceClient.Upload(String ContentType, String Email, Guid FileGuid, String FileName, String HashCode, Int64 Length, String SecurityCode, Stream Stream)
   at Memba.Transfer.PlugIns.WCFPlugIn.Upload(Object state)

Nov 27, 2008 at 2:28 PM
Edited Dec 3, 2008 at 9:04 AM
Hello,

This error has nothing to do with the use case you are describing: dragging and dropping files and renaming the zip file. The serveur has closed the connection which in 99% of the cases is a server configuration issue. IIS and ASP.NET include several settings which  you may have to configure in order to upload/post large files.

First let's cover what the Velodoc XP Edition setup does for you:
  1. On IIS5 and IIS6, in the httpRuntime section of the application web.config file, the setup sets a large value for executionTimeout and maxRequestLength. To understand and modify these settings please refer to http://msdn.microsoft.com/en-us/library/e1f13641.aspx.
  2. On IIS7, in the requestLimits section of the application web.config file, the setup sets a large value for maxAllowedContentLength.To understand and modify these settings please refer to http://msdn.microsoft.com/en-us/library/ms689460.aspx.
Second, let's cover what the Velodoc XP Edition setup is not doing for you, essentially because it affects all applications running on IIS and we like to play in our own back yard:
  1. In the IIS metabase, you may have to consider increasing the values of MaxRequestEntityAllowed, AspMaxRequestEntityAllowed and UploadReadAheadSize. Although these properties essentially relate to ASP applications, they apparently also affect ASP.NET applications as explained here.
  2. In the processModel section of machine.config, you may have to consider increasing the values of  responseDeadlockInterval and responseRestartDeadlockInterval. To understand and modify these settings, please refer to http://msdn.microsoft.com/en-us/library/7w2sway1(VS.71).aspx.
Finally, WCF Services have their own settings. In the following line of web.config, you may have to configure maxReceivedMessageSize, receiveTimeout and sendTimeout:
<binding name="wcfTransferServiceBinding" messageEncoding="Mtom" transferMode="Streamed" maxBufferSize="65536" maxReceivedMessageSize="104857600" receiveTimeout="01:00:00" sendTimeout="00:10:00">

In order to diagnose your specific problem, you need to look at the logs, especially the event log, the IIS log and the Http Error logs as described in http://support.microsoft.com/?id=820729.
Dec 3, 2008 at 3:10 PM
Edited Dec 11, 2008 at 9:39 PM
After further tests, the error above seems to be related to the configuration of wcfTransferServiceBinding in web.config. In Velodoc XP Edition build 081107, the configuration is:
<binding name="wcfTransferServiceBinding" messageEncoding="Mtom" transferMode="Streamed" maxBufferSize="65536" maxReceivedMessageSize="67108864" receiveTimeout="00:05:00" sendTimeout="00:05:00">
which actually means that the server should close the connection should a transfer be more than 64 MB or take more than 5 minutes.

This configuration will be changed to the following in a future build to allow up to 100MB transfers that may take up to 1 hour :
<binding name="wcfTransferServiceBinding" messageEncoding="Mtom" transferMode="Streamed" maxBufferSize="65536" maxReceivedMessageSize="104857600" receiveTimeout="01:00:00" sendTimeout="00:10:00">

maxReceivedMessageSize should be lower than maxRequestLength on IIS6 and maxAllowedContentLength on IIS 7 (see above).