【问题标题】:The remote host closed the connection Error, how fix?远程主机关闭连接错误,如何解决?
【发布时间】:2011-11-27 13:52:04
【问题描述】:

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

【问题讨论】:

  • 你需要找出远程主机关闭连接的原因。
  • 您必须在服务器上查看。例如,服务器上的 Windows 事件日志;也许是 IIS 日志。
  • @John Saunders 嗨,感谢您的评论,请参阅我的编辑 2。
  • windows 日志似乎没有显示这些错误。为什么?
  • 如果服务器吃掉它们,它可能不会显示异常:try{...}catch{}。另外,请尝试在服务器上打开ASP.NET Health Monitoring

标签: c# asp.net elmah windows-server-2008-r2


【解决方案1】:

我在我建立的网站的日志中经常看到这一点。

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

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

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

【讨论】:

【解决方案2】:

当用户取消文件下载时,我遇到了这个错误。在服务器端,它会产生一个带有消息的异常远程主机关闭了连接。错误代码为 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,所以这就是我过滤的依据。

希望这会有所帮助。

【讨论】:

【解决方案3】:

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

在本例中,极慢(或故意)缓慢的客户端可能会导致异常。

我选择通过增加我的套接字的接收超时来解决这个问题,因为我想支持一些特定的较慢的客户端,这些客户端因高 SSL 要求而被征税。

【讨论】:

    【解决方案4】:

    这个聚会有点晚了,但如果它有助于其他人,Response.Close() 在我的情况下导致了异常。

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

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

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

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

    【讨论】:

      【解决方案5】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-02
        • 1970-01-01
        相关资源
        最近更新 更多