首页 新闻 会员 周边 捐助

An existing connection was forcibly closed by the remote host 愿意付费咨询

0
悬赏园豆:100 [待解决问题]

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.

chinaspx的主页 chinaspx | 初学一级 | 园豆:6
提问于:2019-06-20 16:14

UP...

chinaspx 5年前

不能顶帖吗?

chinaspx 5年前
< >
分享
所有回答(2)
0

在客户端调用 WCF 服务后有没有进行 Dispose ?

dudu | 园豆:30778 (高人七级) | 2019-06-20 16:17

客户端是用链接池,TCP链接建立后是保持建立状态,用后还回链接池(类似数据库链接池)所以没有每次使用都dispose关闭。

支持(0) 反对(0) chinaspx | 园豆:6 (初学一级) | 2019-06-20 16:24

@chinaspx: 如果没有 Dispose ,是不会被放回连接池的

支持(0) 反对(0) dudu | 园豆:30778 (高人七级) | 2019-06-20 16:37

@dudu: 这个链接池是我们自己写的链接池机制。使用完就还回我们自己的链接池。

支持(0) 反对(0) chinaspx | 园豆:6 (初学一级) | 2019-06-20 16:44

@chinaspx: 问题可能就出在你们自己实现的连接池

支持(0) 反对(0) dudu | 园豆:30778 (高人七级) | 2019-06-20 16:52

@dudu: 链接池里面就是一个普通的pool队列,这个里面放的是链接对象 System.ServiceModel.ClientBase<T>,每次从pool中取出后会检测CommunicationState状态 ,如果是建立状态就直接使用,否则新创建1个链接,没问题啊。你指的可能有问题,问题可能 在那里?

支持(0) 反对(0) chinaspx | 园豆:6 (初学一级) | 2019-06-20 16:58

@chinaspx: 建议先临时去掉连接池观察一下

支持(0) 反对(0) dudu | 园豆:30778 (高人七级) | 2019-06-20 17:42

@dudu: 每次创建新的TCP链接是不可取的方法。

支持(0) 反对(0) chinaspx | 园豆:6 (初学一级) | 2019-06-21 14:51
0

可能的问题:

  1. 服务端程序重启过
  2. 网络断开过
  3. 服务端有类似心跳检测,主动关闭了tcp连接

建议review代码 客户端,服务端都看,不行的话就上wireshark 抓上它一天的包。客户端记录好错误发生的时间,然后到wireshark里面查错误发生时的前后tcp包。在client或者在server抓都可以。

czd890 | 园豆:14488 (专家六级) | 2019-06-21 18:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册