-->

什么130秒超时被杀死了我的WCF流媒体服务电话吗?(What 130 second timeout

2019-07-18 02:08发布

就在最近,我开始调查在其中,如果客户端发送到服务器之间的等待下去了超过130秒时的CommunicationException生产WCF流一个棘手的问题。

下面是完整的异常:

System.ServiceModel.CommunicationException was unhandled by user code
  HResult=-2146233087
  Message=The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '23:59:59.9110000'.
  Source=mscorlib
  StackTrace:
    Server stack trace: 
       at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.WebRequestOutputStream.Write(Byte[] buffer, Int32 offset, Int32 count)
       at System.IO.BufferedStream.Write(Byte[] array, Int32 offset, Int32 count)
       at System.Xml.XmlStreamNodeWriter.FlushBuffer()
       at System.Xml.XmlStreamNodeWriter.GetBuffer(Int32 count, Int32& offset)
       at System.Xml.XmlUTF8NodeWriter.InternalWriteBase64Text(Byte[] buffer, Int32 offset, Int32 count)
       at System.Xml.XmlBaseWriter.WriteBase64(Byte[] buffer, Int32 offset, Int32 count)
       at System.Xml.XmlDictionaryWriter.WriteValue(IStreamProvider value)
       at System.ServiceModel.Dispatcher.StreamFormatter.Serialize(XmlDictionaryWriter writer, Object[] parameters, Object returnValue)
       at System.ServiceModel.Dispatcher.OperationFormatter.OperationFormatterMessage.OperationFormatterBodyWriter.OnWriteBodyContents(XmlDictionaryWriter writer)
       at System.ServiceModel.Channels.Message.OnWriteMessage(XmlDictionaryWriter writer)
       at System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.WriteMessage(Message message, Stream stream)
       at System.ServiceModel.Channels.HttpOutput.WriteStreamedMessage(TimeSpan timeout)
       at System.ServiceModel.Channels.HttpOutput.Send(TimeSpan timeout)
       at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    Exception rethrown at [0]: 
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at WcfService.IStreamingService.SendStream(MyStreamUpRequest request)
       at Client.Program.<Main>b__0() in c:\Users\jpierson\Documents\Visual Studio 2012\Projects\WcfStreamingTest\Client\Program.cs:line 44
       at System.Threading.Tasks.Task.Execute()
  InnerException: System.IO.IOException
       HResult=-2146232800
       Message=Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.
       Source=System
       StackTrace:
            at System.Net.Sockets.NetworkStream.MultipleWrite(BufferOffsetSize[] buffers)
            at System.Net.ConnectStream.InternalWrite(Boolean async, Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)
            at System.Net.ConnectStream.Write(Byte[] buffer, Int32 offset, Int32 size)
            at System.ServiceModel.Channels.BytesReadPositionStream.Write(Byte[] buffer, Int32 offset, Int32 count)
            at System.ServiceModel.Channels.HttpOutput.WebRequestHttpOutput.WebRequestOutputStream.Write(Byte[] buffer, Int32 offset, Int32 count)
       InnerException: System.Net.Sockets.SocketException
            HResult=-2147467259
            Message=An existing connection was forcibly closed by the remote host
            Source=System
            ErrorCode=10054
            NativeErrorCode=10054
            StackTrace:
                 at System.Net.Sockets.Socket.MultipleSend(BufferOffsetSize[] buffers, SocketFlags socketFlags)
                 at System.Net.Sockets.NetworkStream.MultipleWrite(BufferOffsetSize[] buffers)
            InnerException: 

看来,服务器已过早关闭了连接,由于连接上的活动。 如果我不是给一个脉冲到服务器,在同一时间甚至一个字节,那么我不会产生这种例外,我可以继续无限期地传输数据。 我已经构造一个非常简单的示例应用程序来演示这个它采用basicHttpBinding的与流transferMode和我插入从130秒延迟在客户端上的自定义流实现内的人为延迟。 这模拟类似于这在我的服务呼叫没有数据馈送到WCF基础设施足够快,以满足某种无法辨认的超时值的出现是围绕130第二个被提供来自客户端的流缓冲区欠载运行状态的东西标记。

使用WCF服务跟踪工具,我能够找到与读取信息的HttpException“因为底层的请求已完成客户端断开。不再有可用的HttpContext的。”

从IIS快递跟踪日志文件我看到的条目:“由于线程退出或应用程序请求的I / O操作已中止。(0x800703e3)”

我已经配置了服务器和客户端超时使用值超过130秒大关只是为了排除他们。 我也以发现哪里这个问题是来自,但到目前为止没有运气尝试的idleTimeout在IIS Express和ASP.NET相关的超时值的主机。 我能找到到目前为止最好的信息是在Firefox的问题跟踪评论通过描述一个类似的问题在WCF架构外工作的开发人员。 出于这个原因我猜问题具体可以更关系到IIS7或可能的Windows Server。

在服务器上的Web.config自定义绑定

<binding name="myHttpBindingConfiguration"
         closeTimeout="02:00:00"
         openTimeout="02:00:00"
         receiveTimeout="02:00:00"
         sendTimeout="02:00:00">
  <textMessageEncoding messageVersion="Soap11" />
  <httpTransport maxBufferSize="65536"                        
                 maxReceivedMessageSize="2147483647"
                 maxBufferPoolSize="2147483647"
                 transferMode="Streamed" />
</binding>

在代码客户端配置:

    var binding = new BasicHttpBinding();
    binding.MaxReceivedMessageSize = _maxReceivedMessageSize;
    binding.MaxBufferSize = 65536;
    binding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
    binding.ReaderQuotas.MaxArrayLength = int.MaxValue;
    binding.TransferMode = TransferMode.Streamed;
    binding.ReceiveTimeout = TimeSpan.FromDays(1);
    binding.OpenTimeout = TimeSpan.FromDays(1);
    binding.SendTimeout = TimeSpan.FromDays(1);
    binding.CloseTimeout = TimeSpan.FromDays(1);

为了应对WALS主意,试图看,如果我得到自我任何不同的结果托管我的服务我想补充一点,我这样做了,我发现我得到相同的结果在IIS托管时。 这是什么意思? 我的猜测是,这意味着问题是无论是在WCF或在Windows底层的网络基础设施。 我使用的是Windows 7 64位,我们已经发现,通过运行各种客户端,并在Windows 2008 Server上运行的服务的一部分这个问题。

更新2013年1月15日

我发现了一些新的线索感谢DarkWanderer一旦我意识到,WCF使用HTTP.sys将在Windows 7自托管的情况下这让我寻找到了什么,我可以配置HTTP.sys进行,也什么类型的人报告说,问题对于那些听起来类似于我遇到的HTTP.sys。 这使我位于C日志文件:\ WINDOWS \ SYSTEM32 \ LogFiles文件\ HTTPERR \ httperr1.log出现登录特定类型的HTTP问题上的HTTP.sys的一部分。 在这篇日志我看到每个运行我的测试时间如下类型的日志条目。

2013年1月15日17点17分十二秒127.0.0.1 59111 127.0.0.1 52733 HTTP / 1.1 POST /StreamingService.svc - - Timer_EntityBody -

所以它的下跌寻找条件可能会导致什么Timer_EntityBody误差和IIS7或其他地方有什么设置可能何时以及是否该错误出现在轴承上。

从官方网站IIS :

请求实体主体到达之前连接过期。 当清楚的是一个请求具有一个实体主体,所述HTTP API接通Timer_EntityBody定时器。 最初,此计时器的限制设置为ConnectionTimeout值。 每个该请求接收到另一个数据指示时,HTTP API重置计时器,得到连接在为ConnectionTimeout属性中指定多分钟。

试图修改为ConnectionTimeout属性作为参考以上对ApplicationHost.config建议为IIS快递似乎没有任何区别。 也许IIS快递忽略此配置和使用硬编码值内部? 试图对我自己的东西,我发现有添加,显示,并添加超时值,以便让我去,我想出了下面的命令可惜这样做似乎没有对这个错误有什么影响无论是新的netsh HTTP命令。

netsh的HTTP添加超时timeouttype = IdleConnectionTimeout值= 300

Answer 1:

事实证明,这个问题是由引起的连接超时由HTTP.sys进行使用的值,并可以通过IIS管理器通过高级设置不同地点的规定。 此值由默认配置成当两个头部和主体没有被120秒内接收到超时的连接。 如果接收到的数据的从主体的脉冲然后在服务器重启超时值内的计时器(Timer_EntityBody),则定时器复位以等待附加数据。

这是一样的文档有关Timer_EntityBodyconnectionTimeout指定,但它是很难确定,因为它似乎是IIS快递忽略不管文档是这么说的对ApplicationHost.config在限制元素指定为ConnectionTimeout值。 为了确定这一点,我有我的开发机器上安装完整版的IIS和修改上述托管我的网站有后设置。

由于我们是在Windows 2008上托管IIS下的真正的服务上面的解决方案将工作对我来说不过问题仍然存在如何正确地修改你在哪里,自托管的情况下连接超时值。



Answer 2:

从错误来看:

套接字连接被中止。 这可能是一个错误处理您的信息或接收超时引起的远程主机,或底层网络资源问题被超过。 本地套接字超时是'23:59:59.9110000'

看起来这是一个简单的TCP超时。

您可以通过运行应用程序自托管,然后在控制台中运行以下命令进行验证:

netstat -no |find "xxxxx"

其中xxxxx是服务器进程的PID。 此命令会显示您的服务器已建立的连接和每秒刷新一次。

尝试与客户端连接,并看看会发生什么。 最有可能的,你会看到你的连接“CLOSE_WAIT”或“TIME_WAIT”围绕100-120秒之后 - 这将意味着它是由于超时中止。

这是前人的精力可以解决通过添加以下到您的配置:

<httpTransport maxBufferSize="65536"                        
             maxReceivedMessageSize="2147483647"
             maxBufferPoolSize="2147483647"
             transferMode="Streamed"
             keepAliveEnabled="true" /> <!-- Here -->

参数说明: 这里



Answer 3:

也许远投,但...检查您的IIS应用程序池,如果它使平。 它在高级设置,过程模型分组。



Answer 4:

试试这个,对我来说这解决了这个问题。 问题是,底层内核HTTP.SYS有它自己的超时,它会断开连接。

http://mmmreddy.wordpress.com/2013/07/11/wcf-use-of-http-transport-sharing-persistent-tcp-sessions/

netsh http add timeout timeouttype=idleconnectiontimeout value=120


Answer 5:

你考虑http://support.microsoft.com/kb/946086 ?

我在ISAPI的扩展观察到这种流中断。 根据该suppport注意在IIS 7关闭缓冲之后,寄托都工作过罚款。



文章来源: What 130 second timeout is killing my WCF streaming service call?