远程主机关闭了连接错误,如何修复?

25
我会尽力为您翻译。以下是您需要翻译的内容:

我在我的项目中使用 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)

在使用网站时,我们没有看到这个错误。但是elmah多次发送了这个错误给我。这个错误是什么意思,我该如何修复它?
编辑1: {我的网站用于下载移动文件,有时非常繁忙} {我正在使用Windows Server 2008 R2->远程访问}
编辑2(根据评论): 今天一些Windows信息和警告(没有错误)日志如下:
警告
应用程序池“ASP.NET 4.0(集成)”的进程在关闭期间超出时间限制。进程 ID 为“6764”。
警告
服务于应用程序池“ASP.NET 4.0(集成)”的工作进程“3232”未能在分配的时间内停止协议“http”的监听器通道。数据字段包含错误号。
警告
应用程序池“ASP.NET 4.0(集成)”的进程在关闭期间超出时间限制。进程 ID 为“3928”。

你需要找出远程主机关闭连接的原因。 - John Saunders
你需要在服务器上查看。例如,在服务器上查看Windows事件日志,或者可能是IIS日志。 - John Saunders
@John Saunders您好,感谢您的评论,请查看我的EDIT 2。 - SilverLight
似乎Windows日志没有显示这些错误。为什么? - SilverLight
如果服务器吞掉了异常,可能不会显示它们:try{...}catch{}。此外,请尝试在服务器上启用ASP.NET Health Monitoring - John Saunders
5个回答

39

我在自己建立的网站的日志里经常看到这种异常。

据我所知,这个异常意味着客户端在页面加载完成之前断开了连接(跳转到其他页面/关闭了浏览器)。如果客户端正在下载文件,那么发生此错误的概率会更大,因为他们有更多时间决定放弃/继续操作。

这个错误对用户来说是不可见的* - 所以我从 Elmah 日志中将其移除了。

*该网站只允许经过身份验证的用户。我可以从 Elmah 看到谁遇到了这个错误以及何时遇到。我已经询问了这些用户,并没有一个人报告说在客户端遇到过这个 bug。


@NeilThompson,你能在Elmah上隐藏这种错误吗? - eduardobr
1
@eduardobr 是的。我想我使用了ErrorFiltering。请参见https://code.google.com/p/elmah/wiki/ErrorFiltering。 - Neil Thompson

7

当用户取消文件下载时,我遇到了这个错误。在服务器端,它会产生一个带有消息“远程主机关闭了连接。错误代码为0x800703E3”的异常。然而,该异常没有任何可以单独处理的明确类型。

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

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

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);
        }
    }
}

我注意到这个特定的错误类型具有HResult = -2147023901,所以我正在按此进行筛选。
希望这可以帮到您。

1
HResult -2147023901和0x800703E3的文档 https://www.hresult.info/FACILITY_WIN32/0x800703E3 - Arne H. Bitubekk

3

今天我遇到了这个问题,对我来说,这是因为套接字在等待远程端发送数据时超时了。

在这个例子中,一个非常(或故意)缓慢的客户端可能会导致异常。

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


1

有点晚了,但如果对其他人有帮助的话,我的情况是 Response.Close() 导致了异常。

我看到了 OP 描述的异常,被 Elmah 捕获。

这是由于关闭响应(我支持的代码正在写入响应输出流)导致的:

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

移除 Response.Close(); 后,异常未被抛出。


0

我在MINERGATE遇到了这个问题:/socket_error_the_remote_host_closed_the_connection/。你必须退出并前往C:\Users\yourName\AppData\Local\minergate.ethash-minergate,然后删除此文件夹中的所有文件。祝好运!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接