tcp连接偶尔失败

问题描述

我们的服务器,客户那边可以正常ping通,我们服务器部署了soap服务,使用的是http+tcp,使用的是tcp短链接的形式。但是我们客户端发送消息偶尔失败。
使用了psping工具,ping我们的服务器端口,发现会有ping不通的时候。

.\psping -n 10 -w 2 -h 10  www.baidu.com:80

参考
在这里插入图片描述

解决流程

怀疑是客户网络线路的问题,后来ping了一下百度,发现没有丢包,才继续怀疑是我们服务器的问题(在我们公司这边psping是正常的)。

后来偶然搜到这篇文章,才知道,可能是我们服务器优化过度了。
然后将net.ipv4.tcp_tw_recycle 改成 0 就好了。
查看这个值:
cat /proc/sys/net/ipv4/tcp_tw_recycle
设置这个值:
echo 0 > /proc/sys/net/ipv4/tcp_tw_recycle
使这个值马上生效
sysctl -p

注:这里修改实际修改的是/etc/sysctl.conf 这个文件。

参考2

总结: 只要是有几个客户端(具体数量不定,如果只有一个的话肯定没有问题)在NAT后面,同时访问这个服务器,只要tcp_tw_recycle这个参数开启,就会导致tcp三次握手失败(服务器直接丢弃)。linux也不建议设置这个参数进行优化,linux 4.12版本的内核直接移除了这个参数。

The tcp_tw_recycle was already broken for connections
behind NAT, since the per-destination timestamp is not
monotonically increasing for multiple machines behind
a single destination address.

After the randomization of TCP timestamp offsets
in commit 8a5bd45f6616 (tcp: randomize tcp timestamp offsets
for each connection), the tcp_tw_recycle is broken for all
types of connections for the same reason: the timestamps
received from a single machine is not monotonically increasing,
anymore.

Remove tcp_tw_recycle, since it is not functional. Also, remove
the PAWSPassive SNMP counter since it is only used for
tcp_tw_recycle, and simplify tcp_v4_route_req and tcp_v6_route_req
since the strict argument is only set when tcp_tw_recycle is
enabled.

就这样~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值