最近这两天遇到个很蛋疼的问题,手机通过tcp长连接我们服务器,在wifi与联通3G情况一切正常,可是通过移动cmnet 2G网络访问时很不稳定,时不时会出现connet reset错误,并且不出现的时候就不出现,出现的时候就连续出现.为此通过各种方式排查,开始怀疑服务器有问题,后通过用程序链接服务器,连续几天长连接都一直保持没有任何异常,故排除服务器代码问题.(注:客户端和服务器每3分钟有心跳包交互)
而后接着通过tcpdump(sudo tcpdump -i eth3 host 114.54.1.227 -c 600000)抓包排除异常,开始数据包发送一切正常,出错时是由于客户端发送数据的时候tcp连接变成新的,造成服务器将该连接重置,且端口号都变了,这就纳闷了,怎么会起个新的tcp链接发送数据包过来呢?并且新发送tcp发送数据包都没有经历tcp三次握手建立连接.
查资料显示cmwap使用tcp代理,cmnet直接连接互联网,就算是使用代理那怎么会时不时发送数据会启用一个新的连接,并且该连接都未经历tcp三次握手建立连接?
以前未发现该问题,难道因为我们新的协议使用加密被防火墙给搞的?接下来就一步一步验证引起该问题的原因.
下面直接上tcp抓包数据作为依据,
12:00:38.933885 IP 114.54.1.227.46868 > 61.145.*.*.xmpp-client: Flags [S], seq 1106940554, win 65535, options [mss 1352,sackOK,TS val 14374868 ecr 0,nop,wscale 4], length 0
12:00:38.933935 IP 61.145.*.*.xmpp-client > 114.54.1.227.46868: Flags [S.], seq 2339958167, ack 1106940555, win 14600, options [mss 1460,nop,nop,sackOK,nop,wscale 9], length 0
12:00:39.380709 IP 114.54.1.227.46868 > 61.145.*.*.xmpp-client: Flags [.], ack 1, win 4096, length 0
12:00:39.381537 IP 114.54.1.227.46868 > 61.145.*.*.xmpp-client: Flags [P.], seq 1:157, ack 1, win 4096, length 156
12:00:39.381568 IP 61.145.*.*.xmpp-client > 114.54.1.227.46868: Flags [.], ack 157, win 31, length 0
12:00:39.384912 IP 61.145.*.*.xmpp-client > 114.54.1.227.46868: Flags [P.], seq 1:185, ack 157, win 31, length 184
12:00:39.675838 IP 114.54.1.227.46868 > 61.145.*.*.xmpp-client: Flags [.], ack 185, win 4085, length 0
12:00:53.715910 IP 61.145.*.*.xmpp-client > 114.54.1.227.46868: Flags [.], ack 1492, win 46, length 0
12:00:53.723931 IP 61.145.*.*.xmpp-client > 114.54.1.227.46868: Flags [P.], seq 4107:4326, ack 1492, win 46, length 219
12:00:54.531235 IP 114.54.1.227.46868 > 61.145.*.*.xmpp-client: Flags [.], ack 4326, win 3830, length 0
12:00:59.483701 IP 59.53.67.13.x11 > 61.145.*.*.ms-sql-s: Flags [S], seq 1232666624, win 16384, length 0
12:01:00.139625 IP 114.54.1.227.46868 > 61.145.*.*.xmpp-client: Flags [P.], seq 1492:1735, ack 4326, win 3830, length 243
此处省略N行....................................................................................
12:01:00.148644 IP 61.145.*.*.xmpp-client > 114.54.1.227.46868: Flags [P.], seq 4326:4545, ack 1735, win 48, length 219
12:01:01.291718 IP 61.145.*.*.xmpp-client > 114.54.1.227.46868: Flags [P.], seq 4326:4545, ack 1735, win 48, length 219
12:01:01.595383 IP 114.54.1.227.46868 > 61.145.*.*.xmpp-client: Flags [P.], seq 1492:1735, ack 4326, win 3830, length 243
12:01:01.595407 IP 61.145.*.*.xmpp-client > 114.54.1.227.46868: Flags [.], ack 1735, win 48, options [nop,nop,sack 1 {1492:1735}], length 0
12:01:01.660605 IP 114.54.1.227.46868 > 61.145.*.*.xmpp-client: Flags [.], ack 4545, win 3817, length 0
12:01:01.907224 IP 61.145.*.* > 61.145.124.1: ICMP echo request, id 44639, seq 1, length 64
12:01:01.908322 IP 61.145.124.1 > 61.145.*.*: ICMP echo reply, id 44639, seq 1, length 64
12:01:02.899349 IP 114.54.1.227.46868 > 61.145.*.*.xmpp-client: Flags [.], ack 4545, win 3817, options [nop,nop,sack 1 {4326:4545}], length 0
12:01:23.980713 IP 114.54.1.227.52216 > 61.145.*.*.xmpp-client: Flags [P.], seq 1106942289:1106942532, ack 2339962712, win 3817, length 243
12:01:23.980756 IP 61.145.*.*.xmpp-client > 114.54.1.227.52216: Flags [R], seq 2339962712, win 0, length 0
不知道有没有哪位遇到过同样的问题!!还望多多交流指点!!!