1个WCF应用,NetTCP客户端调服务器端远程方法时(有很多远程方法不定是那1个出现,出现此错误时服务器端cpu/memory不高均正常)。每天极偶尔会出现以下错误:
System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host (详细callstack如链接图)
System.ServiceModel.CommunicationException: 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 '00:01:00'. --->
System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.ServiceModel.Channels.SocketConnection.Write(Byte[] buffer, Int32 offset, Int32 size, Boolean immediate, TimeSpan timeout)
服务端客户端:windows 2008 r2, .net framework 4.5,windows服务器的tcp/ip注册表参数均为默认值
服务器端参数:
NetTcpBinding: listenBacklog="1000",maxConnections="1000" ReceiveTimeout="12:00:00"
ServiceThrottling : maxConcurrentCalls="1000",percall模式
DataContractSerializer :maxItemsInObjectGraph="2147483647"
客户端是用自研链接池POOL,TCP链接建立后是保持建立状态,用后还回链接池(类似数据库链接池)
客户端参数 :
<TcpBinding CloseTimeout="00:01:00" OpenTimeout="00:00:10" ReceiveTimeout="00:01:00" SendTimeout="00:01:00" TransferMode="Buffered" ListenBacklog="1000" MaxBufferPoolSize="1073741824" MaxBufferSize="1073741824" MaxConnections="100" MaxReceivedMessageSize="1073741824" UseDefaultWebProxy="false" HostNameComparisonMode="StrongWildcard">
<ReaderQuotas MaxArrayLength="163840000" MaxBytesPerRead="1048576" MaxDepth="256" MaxNameTableCharCount="163840000" MaxStringContentLength="163840000" />
</TcpBinding>
查了很多资源也没有结果,且无法自测重现,请指点迷津.......感谢感谢。
https://stackoverflow.com/questions/2582036/an-existing-connection-was-forcibly-closed-by-the-remote-host
This generally means that the remote side closed the connection (usually by sending a TCP/IP RST packet). If you're working with a third-party application, the likely causes are:
You are sending malformed data to the application
The network link between the client and server is going down for some reason
You have triggered a bug in the third-party application that caused it to crash
The third-party application has exhausted system resources
It's likely that the first case is what's happening.
You can fire up Wireshark to see exactly what is happening on the wire to narrow down the problem.
Without more specific information, it's unlikely that anyone here can really help you much.
在客户端调用 WCF 服务后有没有进行 Dispose ?
客户端是用链接池,TCP链接建立后是保持建立状态,用后还回链接池(类似数据库链接池)所以没有每次使用都dispose关闭。
@chinaspx: 如果没有 Dispose ,是不会被放回连接池的
@dudu: 这个链接池是我们自己写的链接池机制。使用完就还回我们自己的链接池。
@chinaspx: 问题可能就出在你们自己实现的连接池
@dudu: 链接池里面就是一个普通的pool队列,这个里面放的是链接对象 System.ServiceModel.ClientBase<T>,每次从pool中取出后会检测CommunicationState状态 ,如果是建立状态就直接使用,否则新创建1个链接,没问题啊。你指的可能有问题,问题可能 在那里?
@chinaspx: 建议先临时去掉连接池观察一下
@dudu: 每次创建新的TCP链接是不可取的方法。
可能的问题:
建议review代码 客户端,服务端都看,不行的话就上wireshark 抓上它一天的包。客户端记录好错误发生的时间,然后到wireshark里面查错误发生时的前后tcp包。在client或者在server抓都可以。
UP...
– chinaspx 5年前不能顶帖吗?
– chinaspx 5年前