Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The remote host closed the connection Error, how fix?

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'.

like image 364
SilverLight Avatar asked Nov 27 '11 13:11

SilverLight


People also ask

What causes an existing connection was forcibly closed by the remote host?

​An existing connection was forcibly closed by the remote host​ This error message may occur when migrating a large item (containing large attachments, for instance). ​The Destination system will keep a connection open only for so long, after which the connection will be closed (timeout).


2 Answers

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.

like image 186
Neil Thompson Avatar answered Oct 22 '22 23:10

Neil Thompson


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.

like image 7
Mik Avatar answered Oct 22 '22 23:10

Mik