远程主机关闭连接错误,怎么修复?

时间:2021-06-03 15:13:02

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

我在我的项目中使用elmah - > Elmah.axd来查找错误。有这样的错误:

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?

在使用网站时,我们没有看到此错误。但是elmah多次向我发送此错误。这个错误意味着什么,我该如何解决?

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}

编辑1 {我的网站是下载移动文件,有时它真的很忙} {我正在使用Windows Server 2008 r2->远程访问}

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

编辑2后评论一些Windows信息和警告(没有错误)今天的日志如下所示:

warning

警告

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

为应用程序池“ASP.NET 4.0(集成)”提供服务的进程在关闭期间超出了时间限制。进程ID为'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.

为应用程序池“ASP.NET 4.0(集成)”提供服务的工作进程“3232”未能在指定的时间内停止协议“http”的侦听器通道。数据字段包含错误编号。

warning

警告

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

为应用程序池“ASP.NET 4.0(集成)”提供服务的进程在关闭期间超出了时间限制。流程ID为'3928'。

4 个解决方案

#1


26  

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.

AFAIK该异常意味着客户端在页面加载完成之前断开了连接(转到另一个页面/关闭了浏览器)。如果客户端正在下载文件,则更有可能出现此错误,因为他们有更多时间决定退出/继续。

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

用户看不到该错误* - 所以我刚刚从Elmah日志中删除了它。

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

*该网站仅允许经过身份验证的用户。我可以从Elmah身上看到谁经历过这个错误以及什么时候。我问过用户,并没有一个人报告过在客户端遇到过这个错误。

#2


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.

我选择通过增加套接字上的接收超时来解决它,因为我想支持一些特定的较慢的客户端,这些客户端的SSL要求很高。

#3


2  

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.

当用户取消文件下载时,我遇到了该错误。在服务器端,它会生成带有消息的异常远程主机关闭连接。错误代码是0x800703E3。但是,该异常没有任何可以单独处理的不同类型。

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

为了在ASP.NET MVC中正确处理它,我添加了一个异常记录器:

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

And WebExceptionLogger class implementation:

和WebExceptionLogger类实现:

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.

我注意到这个特定的错误类型有HResult = -2147023901,所以这就是我所过滤的。

Hope this helps.

希望这可以帮助。

#4


0  

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

这个派对迟到了,但万一它帮助了其他人,Response.Close()在我的情况下引起了异常。

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

我看到了由El描述的异常,由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.

删除Response.Close();停止抛出异常。

#1


26  

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.

AFAIK该异常意味着客户端在页面加载完成之前断开了连接(转到另一个页面/关闭了浏览器)。如果客户端正在下载文件,则更有可能出现此错误,因为他们有更多时间决定退出/继续。

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

用户看不到该错误* - 所以我刚刚从Elmah日志中删除了它。

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

*该网站仅允许经过身份验证的用户。我可以从Elmah身上看到谁经历过这个错误以及什么时候。我问过用户,并没有一个人报告过在客户端遇到过这个错误。

#2


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.

我选择通过增加套接字上的接收超时来解决它,因为我想支持一些特定的较慢的客户端,这些客户端的SSL要求很高。

#3


2  

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.

当用户取消文件下载时,我遇到了该错误。在服务器端,它会生成带有消息的异常远程主机关闭连接。错误代码是0x800703E3。但是,该异常没有任何可以单独处理的不同类型。

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

为了在ASP.NET MVC中正确处理它,我添加了一个异常记录器:

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

And WebExceptionLogger class implementation:

和WebExceptionLogger类实现:

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.

我注意到这个特定的错误类型有HResult = -2147023901,所以这就是我所过滤的。

Hope this helps.

希望这可以帮助。

#4


0  

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

这个派对迟到了,但万一它帮助了其他人,Response.Close()在我的情况下引起了异常。

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

我看到了由El描述的异常,由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.

删除Response.Close();停止抛出异常。