The remote host closed the connection Error, how fix?

22

i am using elmah -> Elmah.axd in my project for finding errors.
there is an error like this :

System.Web.HttpException: The remote host closed the connection. The error code is 0x800703E3.
Generated: Sun, 27 Nov 2011 13:06:13 GMT

System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.Web.HttpException (0x800703E3): The remote host closed the connection. The error code is 0x800703E3.
   at System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)
   at System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush()
   at System.Web.HttpResponse.Flush(Boolean finalFlush)
   at System.Web.HttpWriter.TransmitFile(String filename, Int64 offset, Int64 size, Boolean isImpersonating, Boolean supportsLongTransmitFile)
   at System.Web.HttpResponse.TransmitFile(String filename, Int64 offset, Int64 length)
   at SalarSoft.Utility.SP1.ResumeDownload.ProcessDownload(String fileName, String headerFileName)
   at NiceFileExplorer.en.Download.DownloadFile_SalarSoft(String fileName)
   at NiceFileExplorer.en.Download.GoForDownloadFile(String filepath)
   at NiceFileExplorer.en.Download.MainCodes()
   at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

during working with web site, we do n't see this error.
but elmah send this error to me many many times.
what this error mean and how can i fix it?

EDIT 1
{my web site is for downlaod mobile files and some times it's really busy}
{i am using windows server 2008 r2-> remote access}

EDIT 2 after comment
some of windows information and warnings (there is no error) logs for today are like below :

warning

A process serving application pool 'ASP.NET 4.0 (Integrated)' exceeded time limits during shut down. The process id was '6764'.

warning

A worker process '3232' serving application pool 'ASP.NET 4.0 (Integrated)' failed to stop a listener channel for protocol 'http' in the allotted time. The data field contains the error number.

warning

A process serving application pool 'ASP.NET 4.0 (Integrated)' exceeded time limits during shut down. The process id was '3928'.

c#
asp.net
elmah
windows-server-2008-r2
asked on Stack Overflow Nov 27, 2011 by SilverLight • edited Nov 27, 2011 by Yahel

5 Answers

38

I see this a lot in the logs of a website I built.

AFAIK that exception means that the client broke the connection (went to another page / closed the browser) before the page had finished loading. If the client is downloading a file this error is even more likely as they have more time to decide to quit / move on.

The error is not visible to the users* - so I have just removed it from the Elmah logs.

*The site allows only authenticated users. I can see from Elmah who experienced the error and when. I've asked the users and not one person has ever reported experiencing this bug in the client.

answered on Stack Overflow Nov 27, 2011 by Neil Thompson
5

I came across that error when user cancelled file download. On the server side it produces an Exception with message The remote host closed the connection. The error code is 0x800703E3. However, the exception does not have any distinct type that can be handled separately.

In odrer to handle it in ASP.NET MVC properly I added an exception logger:

public static class RegisterFilters
{
    public static void Execute(HttpConfiguration configuration)
    {
        configuration.Services.Add(typeof(IExceptionLogger), new WebExceptionLogger());
    }
}

And WebExceptionLogger class implementation:

public class WebExceptionLogger : ExceptionLogger
{
    private const int RequestCancelledByUserExceptionCode = -2147023901;

    public override void Log(ExceptionLoggerContext context)
    {
        var dependencyScope = context.Request.GetDependencyScope();
        var loggerFactory = dependencyScope.GetService(typeof(ILoggerFactory)) as ILoggerFactory;
        if (loggerFactory == null)
        {
            throw new IoCResolutionException<ILoggerFactory>();
        }

        var logger = loggerFactory.GetTechnicalLogger<WebExceptionLogger>();
        if (context.Exception.HResult == RequestCancelledByUserExceptionCode)
        {
            logger.Info($"Request to url {context.Request.RequestUri} was cancelled by user.");
        }
        else
        {
            logger.Error("An unhandled exception has occured", context.Exception);
        }
    }
}

I noticed that this specifict error type has HResult = -2147023901, so this is what I'm filtering by.

Hope this helps.

answered on Stack Overflow Jan 2, 2018 by Mik
3

I ran into this today, and for me, it was happening because the socket timed out waiting for the remote side to send.

In this example, an extremely (or deliberately) slow client might cause the exception.

I chose to resolve it by increasing the receive timeout on my sockets, since I wanted to support a few specific slower clients that were taxed with the high SSL requirements.

answered on Stack Overflow Nov 15, 2013 by davenpcj
1

Bit late to this party, but in case it helps others, Response.Close() was causing the exception in my situation.

I was seeing the exception, described by the OP, captured by Elmah.

This was occurring due to closing the response (the code I was supporting was writing to the Response output stream):

Response.Flush();
Response.Close();
Response.End();

Removing Response.Close(); stopped the exception being thrown.

answered on Stack Overflow Jul 12, 2017 by strangerinthealps • edited Jul 24, 2017 by strangerinthealps
0

i have faced this problem in MINERGATE /socket_error_the_remote_host_closed_the_connection/ you must sign out and go to C:\Users\yourName\AppData\Local\minergate.ethash-minergate and then delete all files in this folder. good lu

answered on Stack Overflow Aug 11, 2018 by saberjoudaki

User contributions licensed under CC BY-SA 3.0