IM TCP網絡問題分析

心跳異常

香港心跳異常

現象

  • 手表使用香港卡用80端口連接到IM服務器出現心跳急劇下降到60秒的異

  • 出現異常的都是使用80端口,如果是使用8000端口就恢復正常

原因

  • 80端口是Http的常用端口號,連接到IM服務器之后,由于服務器并沒有

把Http和TCP連接服務做區分導致IM的TCP使用80端口連接進來的時候被誤

識別成是一個Http請求,所以就對IM的TCP數據流(TLV格式)進行解析導

致報錯返回了一個Http請求報錯的網頁的Html數據,具體返回的數據格式

客戶端打印是:

<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx/1.8.0</center>

以上是客戶端TCP數據流read到100字節打印出來的數據,是一個Http請求

失敗返回Http狀態碼為400的網頁Html數據

image.png
image.png

以上是tcpdump抓包信息,從抓包信息中可以得知返回的數據確實是一個

Http請求失敗的網頁,對比客戶端程序log打印是吻合的

  • 客戶端的TCP流讀取到上述數據的時候以為是IM服務器正常返回的TLV格

式的數據,所以對read到的數據進行常規的TLV數據解析導致程序解析報錯

(數組越界):

{ConnectionService$6.onRead--1} 
com.xtc.sync.b.b: decode data 

error:java.lang.ArrayIndexOutOfBoundsException: src.length=45 

srcPos=2 dst.length=121 dstPos=0 length=121
at com.xtc.sync.push.common.f.a(Unknown Source)
at com.xtc.sync.push.common.ConnectionService$6.onRead(Unknown 

Source)
at com.xtc.sync.push.common.m.b(Unknown Source)
at com.xtc.sync.push.common.m.a(Unknown Source)
at com.xtc.sync.push.common.m.run(Unknown Source)

客戶端發生數據解析報錯之后會認為當前接收到的數據已經不正確,同時

也會認為后面接續讀取的數據也將不正確,所以會把socket連接關閉重連

java.net.SocketException: Socket closed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:151)
at java.net.SocketInputStream.read(SocketInputStream.java:120)
at java.net.SocketInputStream.read(SocketInputStream.java:106)
at com.xtc.sync.push.common.m.run(Unknown Source)
  • 對于客戶端IM SDK而言
  1. 遇到數據解析異常導致的TCP連接斷開跟網絡NAT超時時間無關,因此不

應該下調心跳周期,但是舊版(1.0.1Realease-1.0.6Realease版本)存在

不足,并沒有對此做過濾處理,所以會不斷的下調心跳

  1. 在遇到數據解析異常斷開重連的時候沒有做時間間隔遞增的重連,所以

斷線后會馬上重連

  1. 客戶端IM SDK在斷線重連之前沒有先切換域名或者端口,選擇拿原來連

接斷開的域名和端口再次嘗試重連,在重試重連失敗的時候才會去切換域

名或者端口,而遇到這種情況,每次嘗試重連TCP都能連接成功,連接成功

之后,數據解析失敗又把TCP連接斷開,然后再拿原來的域名和端口,再重

連,再斷開,如此陷入死循環,無法切換域名或者端口,斷線重連頻率很

高:

Line 12623: 07-16 16:46:31.097  2772  3511 W SYNC-PUSH: 

{ConnectionService$5.onDisconnected--1} connection is 

disconnected
    Line 12860: 07-16 16:46:31.424  2772  3515 W SYNC-PUSH: 

{ConnectionService$5.onDisconnected--1} connection is 

disconnected
    Line 13074: 07-16 16:46:31.758  2772  3519 W SYNC-PUSH: 

{ConnectionService$5.onDisconnected--1} connection is 

disconnected
    Line 13307: 07-16 16:46:32.054  2772  3524 W SYNC-PUSH: 

{ConnectionService$5.onDisconnected--1} connection is 

disconnected
    Line 13560: 07-16 16:46:32.360  2772  3529 W SYNC-PUSH: 

{ConnectionService$5.onDisconnected--1} connection is 

disconnected
    Line 13789: 07-16 16:46:32.687  2772  3531 W SYNC-PUSH: 

{ConnectionService$5.onDisconnected--1} connection is 

disconnected
    Line 14002: 07-16 16:46:32.987  2772  3537 W SYNC-PUSH: 

{ConnectionService$5.onDisconnected--1} connection is 

disconnected
    Line 14214: 07-16 16:46:33.293  2772  3541 W SYNC-PUSH: 

{ConnectionService$5.onDisconnected--1} connection is 

disconnected
    Line 14430: 07-16 16:46:33.648  2772  3545 W SYNC-PUSH: 

{ConnectionService$5.onDisconnected--1} connection is 

disconnected
  • 完整的連接成功,讀取數據,數據解析失敗,斷線重連的log:
07-16 16:46:31.501  2772  2950 I SYNC-PUSH: {p.a--1} 

inetSocketAddress時間間隔(ms):0
07-16 16:46:31.505  2556  2556 D SYNC-PUSH: 

{BaseHandleService.onCreate--1} 

PushConnStatusChangedHandleService created...
07-16 16:46:31.507  2556  2556 I SYNC-PUSH: 

{BaseHandleService.onStartCommand--1} 

PushConnStatusChangedHandleService startId:1
07-16 16:46:31.508  2556  3518 D SYNC-PUSH: 

{BaseHandleService.onHandleIntent--1} 

PushConnStatusChangedHandleService onHandleIntent...
07-16 16:46:31.509  2556  3518 I SYNC-PUSH: 

{PushConnStatusChangedHandleService.a--1} receive 

action:com.xtc.sync.connecting
07-16 16:46:31.513  2556  2556 D SYNC-PUSH: 

{BaseHandleService.onDestroy--1} 

PushConnStatusChangedHandleService destroy...
07-16 16:46:31.578  2772  2950 I SYNC-PUSH: {p.a--1} connect時間

間隔(ms):77
07-16 16:46:31.579  2772  2950 D SYNC-PUSH: {r.a--1} cancel task 

executor
07-16 16:46:31.580  2772  2950 I SYNC-PUSH: {p.r--1} 

lastConnectPeriod:229
07-16 16:46:31.580  2772  2950 W SYNC-PUSH: {p.r--1} connected 

and disconnected is too frequently,do not reset 

reconnectPeriodTag:30000
07-16 16:46:31.582  2772  2950 I SYNC-PUSH: {ConnectionService

$5.onConnected--1} connect to server 

success,hostname:gw.im.okii.com,port:80
07-16 16:46:31.583  2772  2950 D SYNC-PUSH: {ConnectionService

$5.onConnected--1} on thread:Task-Thread#1
07-16 16:46:31.583  2772  2950 D SYNC-PUSH: {r.d--1} start task 

executor
07-16 16:46:31.586  2772  2950 I SYNC-PUSH: 

{AppUtil.isAppActive--1} com.xtc.i3launcher app is active
07-16 16:46:31.587  2772  2950 W ContextImpl: Calling a method in 

the system process without a qualified user: 

android.app.ContextImpl.startService:1357 

android.content.ContextWrapper.startService:613 

com.xtc.sync.push.common.g.a:-1 com.xtc.sync.push.common.k.a:-1 

com.xtc.sync.push.common.ConnectionService$5.onConnected:-1 
07-16 16:46:31.591  2772  2950 I SYNC-PUSH: {g.a--1} notify on 

push connected 

PushConnStatusChangedHandleServicesuccessfully,pkgName:com.xtc.i3

launcher
07-16 16:46:31.597  2556  2556 D SYNC-PUSH: 

{BaseHandleService.onCreate--1} 

PushConnStatusChangedHandleService created...
07-16 16:46:31.598  2556  2556 I SYNC-PUSH: 

{BaseHandleService.onStartCommand--1} 

PushConnStatusChangedHandleService startId:1
07-16 16:46:31.600  2556  3520 D SYNC-PUSH: 

{BaseHandleService.onHandleIntent--1} 

PushConnStatusChangedHandleService onHandleIntent...
07-16 16:46:31.601  2556  3520 I SYNC-PUSH: 

{PushConnStatusChangedHandleService.a--1} receive 

action:com.xtc.sync.connected
07-16 16:46:31.601  2556  3520 I SYNC-PUSH: 

{PushConnStatusChangedHandleService$1.a--1} handle 

action:com.xtc.sync.connected
07-16 16:46:31.602  2556  3520 D SYNC-PUSH: 

{PushConnStatusChangedHandleService.b--1} handleSyncPushConnected
07-16 16:46:31.603  2556  3520 I SYNC-PUSH: 

{StoreUtil.readPublicKey--1} sync 

publicKey:MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDC6kMRGBPWhWvU0Do

HIn6UJgttdmxEZGmRqz1vlE9xAwXIoNbOOuEtKK9YYP4zbMB7xk319Xt1uI9no8Yy

x4cBneRD+3tiBlX6SBLTxDkR1uXxGOPg+agzQ9b29n3FNtFQqyuTTTB4y7FcxKHi

+ndammhtBrMEOwm+LrwRAaD3EQIDAQAB
07-16 16:46:31.604  2772  2950 I SYNC-PUSH: {ConnectionService

$5.onConnected--1} 預埋IP信息:

[{"connectCount":1,"connectFailedCount":0,"connectedSuccessCount"

:1,"disconnectedCount":1,"dns":false,"hostname":"gw.im.okii.com",

"lastConnectFailedCount":0,"port":8000,"start":1500194721268,"ttl

":0,"update":1500194758177}, 

{"connectCount":8,"connectFailedCount":0,"connectedSuccessCount":

7,"disconnectedCount":7,"dns":false,"hostname":"gw.im.okii.com","

lastConnectFailedCount":0,"port":80,"start":1500194721364,"ttl":0

,"update":1500194791500}, 

{"connectCount":0,"connectFailedCount":0,"connectedSuccessCount":

0,"disconnectedCount":0,"dns":false,"hostname":"120.25.129.142","

lastConnectFailedCount":0,"port":1883,"start":1500194721275,"ttl"

:0,"update":0}, 

{"connectCount":0,"connectFailedCount":0,"connectedSuccessCount":

0,"disconnectedCount":0,"dns":false,"hostname":"120.25.129.142","

lastConnectFailedCount":0,"port":8000,"start":1500194721318,"ttl"

:0,"update":0}]
07-16 16:46:31.607  2556  3520 D SYNC-PUSH: {l.b--1} create 

EncryptSetRequestEntity:d:{"a":100021,"b":1,"c":null}
07-16 16:46:31.608  2556  3520 D SYNC-PUSH: {d.a--1} add a 

request,RID:100021
07-16 16:46:31.609  2556  3520 W SYNC-PUSH: {e.a--1} request 

sweeper is started.
07-16 16:46:31.610  2556  3520 D SYNC-PUSH: {d$21.b--1} execute 

enqueueRequest on aidl
07-16 16:46:31.612  2772  2950 I SYNC-PUSH: 

{NetUtil.getSIMType--1} getSIMType:45400,simOperatorName:csl.
07-16 16:46:31.613  2556  3520 I SYNC-PUSH: {d$21.b--1} enqueue 

request entity:d:{"a":100021,"b":1,"c":null}
07-16 16:46:31.613  2772  2950 I SYNC-PUSH: 

{NetUtil.getSIMType--1} getSIMType:csl.
07-16 16:46:31.616  2556  3520 W SYNC-PUSH: {TLVObjectUtil.a--1} 

formatdata error(value is null),name:c,type:class [B
07-16 16:46:31.616  2772  2950 I SYNC-PUSH: 

{NetUtil.getNetworkTag--1} Network tag:csl.-4G
07-16 16:46:31.617  2772  2950 D SYNC-PUSH: {a.a--1} record push 

socket info
07-16 16:46:31.618  2772  2946 D SYNC-PUSH: {ConnectionService

$a.a--1} enqueueSingleSendTask:Binder:2772_4
07-16 16:46:31.618  2772  2950 I SYNC-PUSH: {p.a--1} connect to 

server success {remoteAddress=gw.im.okii.com,remotePort=80}
07-16 16:46:31.622  2772  2946 I SYNC-PUSH: 

{TLVObjectUtil.parseEntity--1} TLVDecodeResult:TLVDecodeResult 

[frameType=0, dataType=32, tagValue=33, length=9, value=

[TLVDecodeResult [frameType=0, dataType=0, tagValue=1, length=4, 

value=[0, 1, -122, -75]], TLVDecodeResult [frameType=0, 

dataType=0, tagValue=10, length=1, value=[1]]]]
07-16 16:46:31.623  2772  2950 W SYNC-PUSH: {p.a--1} cancel 

alarm.
07-16 16:46:31.626  2772  3462 D SYNC-PUSH: {o.h--1} execute the 

send task...
07-16 16:46:31.626  2772  2950 W SYNC-PUSH: {h.a--1} There is a 

hostinfo 

({"connectCount":8,"connectFailedCount":0,"connectedSuccessCount"

:8,"disconnectedCount":7,"dns":false,"hostname":"gw.im.okii.com",

"lastConnectFailedCount":0,"port":80,"start":1500194721364,"ttl":

0,"update":1500194791618}) with the same hostname and port in the 

hostinfo list.
07-16 16:46:31.627  2772  3462 D SYNC-PUSH: 

{ConnectionService.c--1} sendOnBefore
07-16 16:46:31.629  2772  3462 I SYNC-PUSH: {ConnectionService

$6.onWrite--1} write [144] bytes.
07-16 16:46:31.630  2772  2950 I SYNC-PUSH: {b.run--1} connect 

success,network type:4G
07-16 16:46:31.631  1890  2596 D PowerManagerService: 

releaseWakeLockInternal: lock=234890036 [ConnectTask@WakeLock-

21], flags=0x0
07-16 16:46:31.631  1890  2596 D PowerManagerService: 

updateWakeLockSummaryLocked: mWakefulness=Asleep, 

mWakeLockSummary=0x0
07-16 16:46:31.631  1890  2596 D PowerManagerService: Releasing 

suspend blocker "PowerManagerService.WakeLocks".
07-16 16:46:31.632  2772  2950 I SYNC-PUSH: {b.b--1} release a 

connect task wake lock,tag:ConnectTask@WakeLock-

21,acquireDuration:249
07-16 16:46:31.632  2772  3462 D SYNC-PUSH: 

{ConnectionService.b--1} data sent successfully.
07-16 16:46:31.633  2772  2946 D SYNC-PUSH: {r.a--1} execute a 

task,size:0
07-16 16:46:31.636  2556  2556 D SYNC-PUSH: 

{BaseHandleService.onDestroy--1} 

PushConnStatusChangedHandleService destroy...
07-16 16:46:31.638  2772  3462 I SYNC-PUSH: {o.h--1} send data 

success,data:d:{"a":100021,"b":1,"c":[-103,13,105,59,21,-

90,69,86,22,-85,55,-67,66,77,-73,8,-66,96,-124,26,-119,-

61,33,12,120,46,8,76,117,-76,119,57,-21,95,-81,-84,91,-19,-122,-

94,-28,-74,-32,-66,25,-18,84,-46,-88,92,-54,90,0,-75,-

38,23,34,10,-11,-95,-28,32,-37,5,11,-12,20,28,-97,-127,63,-

109,66,-86,-48,-124,8,-95,22,-57,-34,-16,127,17,-42,-93,90,-94,-

43,-123,68,11,-32,-62,33,-79,-72,51,12,62,72,3,87,-28,-108,-52,-

47,-127,77,45,101,-78,-53,-99,90,47,31,12,19,90,27,-57,-1,-69,-

5,-73,-59,100]}
07-16 16:46:31.667  1890  2403 D PowerManagerService: 

acquireWakeLockInternal: lock=228675774, flags=0x1, 

tag="ReadData@WakeLock-1", ws=null, uid=1000, pid=2772
07-16 16:46:31.667  1890  2403 D PowerManagerService: 

updateWakeLockSummaryLocked: mWakefulness=Asleep, 

mWakeLockSummary=0x1
07-16 16:46:31.667  1890  2403 D PowerManagerService: Acquiring 

suspend blocker "PowerManagerService.WakeLocks".
07-16 16:46:31.668  2772  3519 I SYNC-PUSH: {n.a--1} acquire the 

read data wake lock,tag:ReadData@WakeLock-

1,acquireTime:1500194791668
07-16 16:46:31.669  2772  3519 I SYNC-PUSH: {m.run--1} read [323] 

bytes,all buffer bytes:323
07-16 16:46:31.670  2772  3519 I SYNC-PUSH: {m.run--1} read data 

hex:485454502F312E31203430302042616420526571756573740D0A536572766

5723A206E67696E782F312E382E300D0A446174653A2053756E2C203136204A75

6C20323031372030383A34363A333420474D540D0A436F6E74656E742D5479706

53A20746578742F68746D6C0D0A436F6E74656E742D4C656E6774683A20313732

0D0A436F6E6E656374696F6E3A20636C6F73650D0A0D0A3C68746D6C3E0D0A3C6

86561643E3C7469746C653E3430302042616420526571756573743C2F7469746C

653E3C2F686561643E0D0A3C626F6479206267636F6C6F723D227768697465223

E0D0A3C63656E7465723E3C68313E3430302042616420526571756573743C2F68

313E3C2F63656E7465723E0D0A3C68723E3C63656E7465723E6E67696E782F312

E382E303C2F63656E7465723E0D0A3C2F626F64793E0D0A3C2F68746D6C3E0D0A
07-16 16:46:31.671  2772  3519 I SYNC-PUSH: {m.run--1} read data 

binary:[72, 84, 84, 80, 47, 49, 46, 49, 32, 52, 48, 48, 32, 66, 

97, 100, 32, 82, 101, 113, 117, 101, 115, 116, 13, 10, 83, 101, 

114, 118, 101, 114, 58, 32, 110, 103, 105, 110, 120, 47, 49, 46, 

56, 46, 48, 13, 10, 68, 97, 116, 101, 58, 32, 83, 117, 110, 44, 

32, 49, 54, 32, 74, 117, 108, 32, 50, 48, 49, 55, 32, 48, 56, 58, 

52, 54, 58, 51, 52, 32, 71, 77, 84, 13, 10, 67, 111, 110, 116, 

101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 116, 101, 120, 116, 

47, 104, 116, 109, 108, 13, 10, 67, 111, 110, 116, 101, 110, 116, 

45, 76, 101, 110, 103, 116, 104, 58, 32, 49, 55, 50, 13, 10, 67, 

111, 110, 110, 101, 99, 116, 105, 111, 110, 58, 32, 99, 108, 111, 

115, 101, 13, 10, 13, 10, 60, 104, 116, 109, 108, 62, 13, 10, 60, 

104, 101, 97, 100, 62, 60, 116, 105, 116, 108, 101, 62, 52, 48, 

48, 32, 66, 97, 100, 32, 82, 101, 113, 117, 101, 115, 116, 60, 

47, 116, 105, 116, 108, 101, 62, 60, 47, 104, 101, 97, 100, 62, 

13, 10, 60, 98, 111, 100, 121, 32, 98, 103, 99, 111, 108, 111, 

114, 61, 34, 119, 104, 105, 116, 101, 34, 62, 13, 10, 60, 99, 

101, 110, 116, 101, 114, 62, 60, 104, 49, 62, 52, 48, 48, 32, 66, 

97, 100, 32, 82, 101, 113, 117, 101, 115, 116, 60, 47, 104, 49, 

62, 60, 47, 99, 101, 110, 116, 101, 114, 62, 13, 10, 60, 104, 

114, 62, 60, 99, 101, 110, 116, 101, 114, 62, 110, 103, 105, 110, 

120, 47, 49, 46, 56, 46, 48, 60, 47, 99, 101, 110, 116, 101, 114, 

62, 13, 10, 60, 47, 98, 111, 100, 121, 62, 13, 10, 60, 47, 104, 

116, 109, 108, 62, 13, 10]
07-16 16:46:31.672  2772  3519 I SYNC-PUSH: {m.run--1} read data 

test format:HTTP/1.1 400 Bad Request
07-16 16:46:31.672  2772  3519 I SYNC-PUSH: Server: nginx/1.8.0
07-16 16:46:31.672  2772  3519 I SYNC-PUSH: Date: Sun, 16 Jul 

2017 08:46:34 GMT
07-16 16:46:31.672  2772  3519 I SYNC-PUSH: Content-Type: 

text/html
07-16 16:46:31.672  2772  3519 I SYNC-PUSH: Content-Length: 172
07-16 16:46:31.672  2772  3519 I SYNC-PUSH: Connection: close
07-16 16:46:31.672  2772  3519 I SYNC-PUSH: 
07-16 16:46:31.672  2772  3519 I SYNC-PUSH: <html>
07-16 16:46:31.672  2772  3519 I SYNC-PUSH: <head><title>400 Bad 

Request</title></head>
07-16 16:46:31.672  2772  3519 I SYNC-PUSH: <body 

bgcolor="white">
07-16 16:46:31.672  2772  3519 I SYNC-PUSH: <center><h1>400 Bad 

Request</h1></center>
07-16 16:46:31.672  2772  3519 I SYNC-PUSH: 

<hr><center>nginx/1.8.0</center>
07-16 16:46:31.672  2772  3519 I SYNC-PUSH: </body>
07-16 16:46:31.672  2772  3519 I SYNC-PUSH: </html>
07-16 16:46:31.673  2772  3519 I SYNC-PUSH: {m.a--1} cut data[86] 

bytes,rest buffer bytes:237
07-16 16:46:31.674  2772  3519 I SYNC-PUSH: {m.a--1} 

hex:485454502F312E31203430302042616420526571756573740D0A536572766

5723A206E67696E782F312E382E300D0A446174653A2053756E2C203136204A75

6C20323031372030383A34363A333420474D540D0A436F
07-16 16:46:31.675  2772  3519 I SYNC-PUSH: {m.a--1} binary:[72, 

84, 84, 80, 47, 49, 46, 49, 32, 52, 48, 48, 32, 66, 97, 100, 32, 

82, 101, 113, 117, 101, 115, 116, 13, 10, 83, 101, 114, 118, 101, 

114, 58, 32, 110, 103, 105, 110, 120, 47, 49, 46, 56, 46, 48, 13, 

10, 68, 97, 116, 101, 58, 32, 83, 117, 110, 44, 32, 49, 54, 32, 

74, 117, 108, 32, 50, 48, 49, 55, 32, 48, 56, 58, 52, 54, 58, 51, 

52, 32, 71, 77, 84, 13, 10, 67, 111]
07-16 16:46:31.675  2772  3519 I SYNC-PUSH: {ConnectionService

$6.onRead--1} read [86] bytes
07-16 16:46:31.677  2772  3519 I SYNC-PUSH: 

{TLVObjectUtil.parseEntity--1} TLVDecodeResult:TLVDecodeResult 

[frameType=64, dataType=0, tagValue=8, length=84, value=[84, 80, 

47, 49, 46, 49, 32, 52, 48, 48, 32, 66, 97, 100, 32, 82, 101, 

113, 117, 101, 115, 116, 13, 10, 83, 101, 114, 118, 101, 114, 58, 

32, 110, 103, 105, 110, 120, 47, 49, 46, 56, 46, 48, 13, 10, 68, 

97, 116, 101, 58, 32, 83, 117, 110, 44, 32, 49, 54, 32, 74, 117, 

108, 32, 50, 48, 49, 55, 32, 48, 56, 58, 52, 54, 58, 51, 52, 32, 

71, 77, 84, 13, 10, 67, 111]]
07-16 16:46:31.679  2772  3519 D :       : {f.a--1} decode no 

encrypt data
07-16 16:46:31.680  2772  3519 I SYNC-PUSH: {f.a--1} decode 

data:e:{"b":0}
07-16 16:46:31.682  2772  3519 I SYNC-PUSH: 

{ConnectionService.a--1} receive response entity:e:{"b":0}
07-16 16:46:31.683  1890  1902 D PowerManagerService: 

releaseWakeLockInternal: lock=228675774 [ReadData@WakeLock-1], 

flags=0x0
07-16 16:46:31.684  1890  1902 D PowerManagerService: 

updateWakeLockSummaryLocked: mWakefulness=Asleep, 

mWakeLockSummary=0x0
07-16 16:46:31.684  1890  1902 D PowerManagerService: Releasing 

suspend blocker "PowerManagerService.WakeLocks".
07-16 16:46:31.685  2772  3519 I SYNC-PUSH: {n.a--1} release read 

data wake lock,tag:ReadData@WakeLock-1,acquireDuration:17
07-16 16:46:31.686  2772  3519 W SYNC-PUSH: {b.e--1} heartbeat 

scheduler is not started
07-16 16:46:31.688  2772  3519 D SYNC-PUSH: 

{ConnectionService.A--1} heartbeat response on time:08:00:00
07-16 16:46:31.691  2772  3519 I SYNC-PUSH: {m.a--1} cut data

[118] bytes,rest buffer bytes:119
07-16 16:46:31.692  2772  3519 I SYNC-PUSH: {m.a--1} 

hex:6E74656E742D547970653A20746578742F68746D6C0D0A436F6E74656E742

D4C656E6774683A203137320D0A436F6E6E656374696F6E3A20636C6F73650D0A

0D0A3C68746D6C3E0D0A3C686561643E3C7469746C653E3430302042616420526

571756573743C2F7469746C653E3C2F686561643E0D0A
07-16 16:46:31.692  2772  3519 I SYNC-PUSH: {m.a--1} binary:[110, 

116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 116, 101, 120, 

116, 47, 104, 116, 109, 108, 13, 10, 67, 111, 110, 116, 101, 110, 

116, 45, 76, 101, 110, 103, 116, 104, 58, 32, 49, 55, 50, 13, 10, 

67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 58, 32, 99, 108, 

111, 115, 101, 13, 10, 13, 10, 60, 104, 116, 109, 108, 62, 13, 

10, 60, 104, 101, 97, 100, 62, 60, 116, 105, 116, 108, 101, 62, 

52, 48, 48, 32, 66, 97, 100, 32, 82, 101, 113, 117, 101, 115, 

116, 60, 47, 116, 105, 116, 108, 101, 62, 60, 47, 104, 101, 97, 

100, 62, 13, 10]
07-16 16:46:31.693  2772  3519 I SYNC-PUSH: {ConnectionService

$6.onRead--1} read [118] bytes
07-16 16:46:31.699  2772  3519 E SYNC-PUSH: {f.a--1} 
07-16 16:46:31.699  2772  3519 E SYNC-PUSH: 

java.lang.ArrayIndexOutOfBoundsException: src.length=45 srcPos=2 

dst.length=121 dstPos=0 length=121
07-16 16:46:31.699  2772  3519 E SYNC-PUSH:     at 

java.lang.System.arraycopy(Native Method)
07-16 16:46:31.699  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.c.d.a(Unknown Source)
07-16 16:46:31.699  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.c.d.a(Unknown Source)
07-16 16:46:31.699  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.c.d.a(Unknown Source)
07-16 16:46:31.699  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.c.d.a(Unknown Source)
07-16 16:46:31.699  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.c.d.a(Unknown Source)
07-16 16:46:31.699  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.c.d.a(Unknown Source)
07-16 16:46:31.699  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.c.d.a(Unknown Source)
07-16 16:46:31.699  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.c.d.a(Unknown Source)
07-16 16:46:31.699  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.util.TLVObjectUtil.parseEntity(Unknown Source)
07-16 16:46:31.699  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.push.common.f.a(Unknown Source)
07-16 16:46:31.699  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.push.common.ConnectionService$6.onRead(Unknown 

Source)
07-16 16:46:31.699  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.push.common.m.b(Unknown Source)
07-16 16:46:31.699  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.push.common.m.a(Unknown Source)
07-16 16:46:31.699  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.push.common.m.run(Unknown Source)
07-16 16:46:31.700  2772  3519 E SYNC-PUSH: {f.a--1} error 

data,length:118,content 

hex:6E74656E742D547970653A20746578742F68746D6C0D0A436F6E74656E742

D4C656E6774683A203137320D0A436F6E6E656374696F6E3A20636C6F73650D0A

0D0A3C68746D6C3E0D0A3C686561643E3C7469746C653E3430302042616420526

571756573743C2F7469746C653E3C2F686561643E0D0A
07-16 16:46:31.701  2556  2756 D SYNC-PUSH: {e.c--1} sweep 

request...
07-16 16:46:31.701  2772  3519 E SYNC-PUSH: {f.a--1} error 

data,length:118,content binary:[110, 116, 101, 110, 116, 45, 84, 

121, 112, 101, 58, 32, 116, 101, 120, 116, 47, 104, 116, 109, 

108, 13, 10, 67, 111, 110, 116, 101, 110, 116, 45, 76, 101, 110, 

103, 116, 104, 58, 32, 49, 55, 50, 13, 10, 67, 111, 110, 110, 

101, 99, 116, 105, 111, 110, 58, 32, 99, 108, 111, 115, 101, 13, 

10, 13, 10, 60, 104, 116, 109, 108, 62, 13, 10, 60, 104, 101, 97, 

100, 62, 60, 116, 105, 116, 108, 101, 62, 52, 48, 48, 32, 66, 97, 

100, 32, 82, 101, 113, 117, 101, 115, 116, 60, 47, 116, 105, 116, 

108, 101, 62, 60, 47, 104, 101, 97, 100, 62, 13, 10]
07-16 16:46:31.702  2772  3519 E SYNC-PUSH: {f.a--1} error data 

test format:ntent-Type: text/html
07-16 16:46:31.702  2772  3519 E SYNC-PUSH: Content-Length: 172
07-16 16:46:31.702  2772  3519 E SYNC-PUSH: Connection: close
07-16 16:46:31.702  2772  3519 E SYNC-PUSH: 
07-16 16:46:31.702  2772  3519 E SYNC-PUSH: <html>
07-16 16:46:31.702  2772  3519 E SYNC-PUSH: <head><title>400 Bad 

Request</title></head>
07-16 16:46:31.703  2772  3519 D SYNC-PUSH: {p.c--1} connection 

has release.
07-16 16:46:31.704  2772  3519 W SYNC-PUSH: {p.a--1} cancel 

connect
07-16 16:46:31.707  2772  3519 W SYNC-PUSH: {p.a--1} cancel 

alarm.
07-16 16:46:31.708  2772  3519 D SYNC-PUSH: {r.a--1} cancel task 

executor
07-16 16:46:31.709  2772  3519 D SYNC-PUSH: {r.a--1} execute a 

task,size:0
07-16 16:46:31.709  2772  2950 D SYNC-PUSH: {b.run--1} run 

connect task...
07-16 16:46:31.710  1890  2596 D PowerManagerService: 

acquireWakeLockInternal: lock=18235040, flags=0x1, 

tag="ConnectTask@WakeLock-23", ws=null, uid=1000, pid=2772
07-16 16:46:31.710  1890  2596 D PowerManagerService: 

updateWakeLockSummaryLocked: mWakefulness=Asleep, 

mWakeLockSummary=0x1
07-16 16:46:31.711  1890  2596 D PowerManagerService: Acquiring 

suspend blocker "PowerManagerService.WakeLocks".
07-16 16:46:31.714  2772  3519 I SYNC-PUSH: {p.a--1} enqueue a 

connect task:b{hostInfo:

{"connectCount":8,"connectFailedCount":0,"connectedSuccessCount":

8,"disconnectedCount":7,"dns":false,"hostname":"gw.im.okii.com","

lastConnectFailedCount":0,"port":80,"start":1500194721364,"ttl":0

,"update":1500194791618},isAlarm:true}
07-16 16:46:31.717  2772  3519 I SYNC-PUSH: 

{ConnectionService.a--1} connect status:false
07-16 16:46:31.718  2772  2950 I SYNC-PUSH: {b.a--1} acquire a 

connect task wake lock,tag:ConnectTask@WakeLock-23
07-16 16:46:31.718  2772  2950 D SYNC-PUSH: {p.a--1} to close the 

previous socket before create a new socket...
07-16 16:46:31.719  2772  2950 D SYNC-PUSH: {p.c--1} connection 

has release.
07-16 16:46:31.724  2772  3519 E SYNC-PUSH: {ConnectionService

$6.onRead--1} 
07-16 16:46:31.724  2772  3519 E SYNC-PUSH: com.xtc.sync.b.b: 

decode data error:java.lang.ArrayIndexOutOfBoundsException: 

src.length=45 srcPos=2 dst.length=121 dstPos=0 length=121
07-16 16:46:31.724  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.push.common.f.a(Unknown Source)
07-16 16:46:31.724  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.push.common.ConnectionService$6.onRead(Unknown 

Source)
07-16 16:46:31.724  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.push.common.m.b(Unknown Source)
07-16 16:46:31.724  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.push.common.m.a(Unknown Source)
07-16 16:46:31.724  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.push.common.m.run(Unknown Source)
07-16 16:46:31.728  2772  3519 I SYNC-PUSH: {m.a--1} cut data

[100] bytes,rest buffer bytes:19
07-16 16:46:31.730  2772  3519 I SYNC-PUSH: {m.a--1} 

hex:3C626F6479206267636F6C6F723D227768697465223E0D0A3C63656E74657

23E3C68313E3430302042616420526571756573743C2F68313E3C2F63656E7465

723E0D0A3C68723E3C63656E7465723E6E67696E782F312E382E303C2F63656E7

465723E0D
07-16 16:46:31.731  2772  3519 I SYNC-PUSH: {m.a--1} binary:[60, 

98, 111, 100, 121, 32, 98, 103, 99, 111, 108, 111, 114, 61, 34, 

119, 104, 105, 116, 101, 34, 62, 13, 10, 60, 99, 101, 110, 116, 

101, 114, 62, 60, 104, 49, 62, 52, 48, 48, 32, 66, 97, 100, 32, 

82, 101, 113, 117, 101, 115, 116, 60, 47, 104, 49, 62, 60, 47, 

99, 101, 110, 116, 101, 114, 62, 13, 10, 60, 104, 114, 62, 60, 

99, 101, 110, 116, 101, 114, 62, 110, 103, 105, 110, 120, 47, 49, 

46, 56, 46, 48, 60, 47, 99, 101, 110, 116, 101, 114, 62, 13]
07-16 16:46:31.732  2772  3519 I SYNC-PUSH: {ConnectionService

$6.onRead--1} read [100] bytes
07-16 16:46:31.736  2772  3519 E SYNC-PUSH: {f.a--1} 
07-16 16:46:31.736  2772  3519 E SYNC-PUSH: 

java.lang.ArrayIndexOutOfBoundsException: src.length=98 srcPos=2 

dst.length=100 dstPos=0 length=100
07-16 16:46:31.736  2772  3519 E SYNC-PUSH:     at 

java.lang.System.arraycopy(Native Method)
07-16 16:46:31.736  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.c.d.a(Unknown Source)
07-16 16:46:31.736  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.c.d.a(Unknown Source)
07-16 16:46:31.736  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.c.d.a(Unknown Source)
07-16 16:46:31.736  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.c.d.a(Unknown Source)
07-16 16:46:31.736  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.util.TLVObjectUtil.parseEntity(Unknown Source)
07-16 16:46:31.736  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.push.common.f.a(Unknown Source)
07-16 16:46:31.736  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.push.common.ConnectionService$6.onRead(Unknown 

Source)
07-16 16:46:31.736  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.push.common.m.b(Unknown Source)
07-16 16:46:31.736  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.push.common.m.a(Unknown Source)
07-16 16:46:31.736  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.push.common.m.run(Unknown Source)
07-16 16:46:31.737  2772  3519 E SYNC-PUSH: {f.a--1} error 

data,length:100,content 

hex:3C626F6479206267636F6C6F723D227768697465223E0D0A3C63656E74657

23E3C68313E3430302042616420526571756573743C2F68313E3C2F63656E7465

723E0D0A3C68723E3C63656E7465723E6E67696E782F312E382E303C2F63656E7

465723E0D
07-16 16:46:31.738  2772  3519 E SYNC-PUSH: {f.a--1} error 

data,length:100,content binary:[60, 98, 111, 100, 121, 32, 98, 

103, 99, 111, 108, 111, 114, 61, 34, 119, 104, 105, 116, 101, 34, 

62, 13, 10, 60, 99, 101, 110, 116, 101, 114, 62, 60, 104, 49, 62, 

52, 48, 48, 32, 66, 97, 100, 32, 82, 101, 113, 117, 101, 115, 

116, 60, 47, 104, 49, 62, 60, 47, 99, 101, 110, 116, 101, 114, 

62, 13, 10, 60, 104, 114, 62, 60, 99, 101, 110, 116, 101, 114, 

62, 110, 103, 105, 110, 120, 47, 49, 46, 56, 46, 48, 60, 47, 99, 

101, 110, 116, 101, 114, 62, 13]
07-16 16:46:31.739  2772  3519 E SYNC-PUSH: {f.a--1} error data 

test format:<body bgcolor="white">
07-16 16:46:31.739  2772  3519 E SYNC-PUSH: <center><h1>400 Bad 

Request</h1></center>
07-16 16:46:31.739  2772  3519 E SYNC-PUSH: 

<hr><center>nginx/1.8.0</center>
07-16 16:46:31.739  2772  3519 W SYNC-PUSH: {p.a--1} cancel 

connect
07-16 16:46:31.742  2772  3519 W SYNC-PUSH: {p.a--1} cancel 

alarm.
07-16 16:46:31.743  2772  3519 D SYNC-PUSH: {r.a--1} cancel task 

executor
07-16 16:46:31.745  2772  3519 D SYNC-PUSH: {r.a--1} execute a 

task,size:1
07-16 16:46:31.748  2772  3519 I SYNC-PUSH: {p.a--1} enqueue a 

connect task:b{hostInfo:

{"connectCount":8,"connectFailedCount":0,"connectedSuccessCount":

8,"disconnectedCount":7,"dns":false,"hostname":"gw.im.okii.com","

lastConnectFailedCount":0,"port":80,"start":1500194721364,"ttl":0

,"update":1500194791618},isAlarm:true}
07-16 16:46:31.749  2772  3519 I SYNC-PUSH: 

{ConnectionService.a--1} connect status:false
07-16 16:46:31.750  2772  3519 E SYNC-PUSH: {ConnectionService

$6.onRead--1} 
07-16 16:46:31.750  2772  3519 E SYNC-PUSH: com.xtc.sync.b.b: 

decode data error:java.lang.ArrayIndexOutOfBoundsException: 

src.length=98 srcPos=2 dst.length=100 dstPos=0 length=100
07-16 16:46:31.750  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.push.common.f.a(Unknown Source)
07-16 16:46:31.750  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.push.common.ConnectionService$6.onRead(Unknown 

Source)
07-16 16:46:31.750  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.push.common.m.b(Unknown Source)
07-16 16:46:31.750  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.push.common.m.a(Unknown Source)
07-16 16:46:31.750  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.push.common.m.run(Unknown Source)
07-16 16:46:31.755  2772  3519 E SYNC-PUSH: {m.run--1} 
07-16 16:46:31.755  2772  3519 E SYNC-PUSH: 

java.net.SocketException: Socket closed
07-16 16:46:31.755  2772  3519 E SYNC-PUSH:     at 

java.net.SocketInputStream.socketRead0(Native Method)
07-16 16:46:31.755  2772  3519 E SYNC-PUSH:     at 

java.net.SocketInputStream.read(SocketInputStream.java:151)
07-16 16:46:31.755  2772  3519 E SYNC-PUSH:     at 

java.net.SocketInputStream.read(SocketInputStream.java:120)
07-16 16:46:31.755  2772  3519 E SYNC-PUSH:     at 

java.net.SocketInputStream.read(SocketInputStream.java:106)
07-16 16:46:31.755  2772  3519 E SYNC-PUSH:     at 

com.xtc.sync.push.common.m.run(Unknown Source)
07-16 16:46:31.755  2772  3519 I SYNC-PUSH: {m.run--1} buffer 

size == 19,continue to read buffer...
07-16 16:46:31.756  2772  3519 W SYNC-PUSH: {m.run--1} 

onInterrupt:false
07-16 16:46:31.757  2772  3519 D SYNC-PUSH: {p$1.onInterrupt--1} 

reconnect:false
07-16 16:46:31.757  2772  3519 W SYNC-PUSH: {p.s--1} connection 

is disconnected,connected time is:1500194791579,disconnected time 

is:1500194791757,connected time of duration 

is:178,minConnectPeriod format:00:00:01
07-16 16:46:31.758  2772  3519 W SYNC-PUSH: {ConnectionService

$5.onDisconnected--1} connection is disconnected
07-16 16:46:31.759  2772  3519 D SYNC-PUSH: {ConnectionService

$5.onDisconnected--1} on thread:Socket-Thread
07-16 16:46:31.759  2772  3519 D SYNC-PUSH: {r.e--1} stop task 

executor
07-16 16:46:31.761  2772  3519 D SYNC-PUSH: {PhoneStore.put--1} 

commit:false
07-16 16:46:31.762  2772  3519 I SYNC-PUSH: 

{StoreUtil.saveRegistInfo--1} save registInfo 

finished,regist_info:

{"login":false,"registId":25776307,"registToken":"bd642bf2aef4433

0a9102284b9e5fd8b"}
07-16 16:46:31.769  2772  3519 I SYNC-PUSH: 

{SDCardUtil.saveSyncRegistInfo--1} save syncRegistInfo to sdcard 

successful,syncRegistInfo:SyncRegistInfo{registId=25776307, 

registToken='bd642bf2aef44330a9102284b9e5fd8b', login=false}
07-16 16:46:31.777  2772  3519 I SYNC-PUSH: 

{NetUtil.getSIMType--1} getSIMType:45400,simOperatorName:csl.
07-16 16:46:31.778  2772  3519 I SYNC-PUSH: 

{NetUtil.getSIMType--1} getSIMType:csl.
07-16 16:46:31.780  2772  3519 I SYNC-PUSH: 

{NetUtil.getNetworkTag--1} Network tag:csl.-4G
07-16 16:46:31.781  2772  3519 W SYNC-PUSH: {ConnectionService

$5.onDisconnected--1} connected duration is 178 which is too 

short,so do not adjust heartbeat on connection disconnected
07-16 16:46:31.788  2772  3519 I SYNC-PUSH: 

{NetUtil.getSIMType--1} getSIMType:45400,simOperatorName:csl.
07-16 16:46:31.789  2772  3519 I SYNC-PUSH: 

{NetUtil.getSIMType--1} getSIMType:csl.
07-16 16:46:31.793  2772  3519 I SYNC-PUSH: 

{NetUtil.getNetworkTag--1} Network tag:csl.-4G
07-16 16:46:31.796  2772  3519 D SYNC-PUSH: {f.h--1} cancel 

heartbeat,requestCode:37457
07-16 16:46:31.796  2772  3519 D SYNC-PUSH: {f.b--1} stop 

heartbeat...
  • 具體log分析流程
  1. connect to server success,hostname:gw.im.okii.com,port:80代表

TCP連接IM服務器gw.im.okii.com成功,連接端口為80

  1. read [323] bytes,all buffer bytes:323表示客戶端杜渠道服務端寫

入的TCP數據為323個字節

  1. cut data[86] bytes,rest buffer bytes:237表示客戶端開始對讀取到

的數據進行解析

  1. java.lang.ArrayIndexOutOfBoundsException: src.length=45

srcPos=2 dst.length=121 dstPos=0 length=121表示數據解析報錯,數組

越界

  1. 對與解析錯誤的數據做打印輸出,然后關閉TCP連接進行重連:
07-16 16:46:31.702  2772  3519 E SYNC-PUSH: {f.a--1} error data 

test format:ntent-Type: text/html
07-16 16:46:31.702  2772  3519 E SYNC-PUSH: Content-Length: 172
07-16 16:46:31.702  2772  3519 E SYNC-PUSH: Connection: close
07-16 16:46:31.702  2772  3519 E SYNC-PUSH: 
07-16 16:46:31.702  2772  3519 E SYNC-PUSH: <html>
07-16 16:46:31.702  2772  3519 E SYNC-PUSH: <head><title>400 Bad 

Request</title></head>
07-16 16:46:31.703  2772  3519 D SYNC-PUSH: {p.c--1} connection 

has release.
07-16 16:46:31.704  2772  3519 W SYNC-PUSH: {p.a--1} cancel 

connect
07-16 16:46:31.707  2772  3519 W SYNC-PUSH: {p.a--1} cancel 

alarm.
07-16 16:46:31.708  2772  3519 D SYNC-PUSH: {r.a--1} cancel task 

executor

解決方案

  • 服務器把Http和TCP服務做區分,避免對使用80端口連接進來的IM服務錯

誤的識別成Http短連接

  • 客戶端優化心跳下調策略,在遇到數據解析錯誤導致的TCP斷開的時候,

不下調心跳間隔,避免心跳誤下調,影響心跳探測的準確性

  • 客戶端優化重連策略,在遇到數據解析錯誤導致的斷開重連的時候要做

時間間隔遞增重連,避免頻繁的重連

  • 客戶端新程序不再允許使用80端口去連接IM服務器,不單單是80端口,

一些常用的端口,例如8080,443,1000一下的端口等都不能使用,避免出

現類似的問題

  • 客戶端在每一次重連之前首先切換下域名或者端口,避免用同一個域名

和端口去再次連接IM服務器導致無法跳出這個域名和端口連接造成的異常

,如果客戶端有成功切換域名或者端口,那么遇到上述情況會立即切換到

8000端口,次數連接就會恢復正常

解決效果

  • 服務器在對Http和TCP服務做了區分之后,從大數據分析來看,香港幾臺

有上傳大數據的手表分析來看全部都恢復正常使用

  • 等待客戶端的新版IM程序測試更新

青海心跳異常

現象

  • 青海心跳周期異常的現象和香港的現象一模一樣

原因

  • 客戶端使用80端口連接gw.im.okii.com域名的時候被運營商劫持到了

111.44.228.186這個地址(正確的應該是106.75.86.52),而被誤識別成

Http短鏈接,然后返回一個錯誤的網頁html數據,然后客戶端接收到數據

后解析報錯,導致頻繁的斷線重連和心跳下調

  • 客戶端的心跳下調策略和重連策略存在缺陷,遇到這種情況后會導致心

跳誤下調,重連頻繁,與香港的原因類似

{TCPConnection.a--1} local 

dns,hostname:gw.im.okii.com,ip:111.44.228.186

gw.im.okii.com本地dns解析出來的ip為111.44.228.186,由此確認是被劫

持了

07-27 16:35:52.384  2740  8726 E SYNC-PUSH: {DataCoder.a--1} 
07-27 16:35:52.384  2740  8726 E SYNC-PUSH: 

java.lang.ArrayIndexOutOfBoundsException: src.length=13 srcPos=2 

dst.length=67 dstPos=0 length=67
07-27 16:35:52.384  2740  8726 E SYNC-PUSH:     at 

java.lang.System.arraycopy(Native Method)
07-27 16:35:52.384  2740  8726 E SYNC-PUSH:     at 

com.xtc.sync.tlv.TLVDecoder.a(Unknown Source)
07-27 16:35:52.384  2740  8726 E SYNC-PUSH:     at 

com.xtc.sync.tlv.TLVDecoder.a(Unknown Source)
07-27 16:35:52.384  2740  8726 E SYNC-PUSH:     at 

com.xtc.sync.tlv.TLVDecoder.a(Unknown Source)
07-27 16:35:52.384  2740  8726 E SYNC-PUSH:     at 

com.xtc.sync.tlv.TLVDecoder.a(Unknown Source)
07-27 16:35:52.384  2740  8726 E SYNC-PUSH:     at 

com.xtc.sync.util.TLVObjectUtil.parseEntity(Unknown Source)
07-27 16:35:52.384  2740  8726 E SYNC-PUSH:     at 

com.xtc.sync.push.common.DataCoder.a(Unknown Source)
07-27 16:35:52.384  2740  8726 E SYNC-PUSH:     at 

com.xtc.sync.push.common.ConnectionService$6.onRead(Unknown 

Source)
07-27 16:35:52.384  2740  8726 E SYNC-PUSH:     at 

com.xtc.sync.push.common.ReadAndWriteDataThread.b(Unknown Source)
07-27 16:35:52.384  2740  8726 E SYNC-PUSH:     at 

com.xtc.sync.push.common.ReadAndWriteDataThread.a(Unknown Source)
07-27 16:35:52.384  2740  8726 E SYNC-PUSH:     at 

com.xtc.sync.push.common.ReadAndWriteDataThread.run(Unknown 

Source)

07-27 16:35:52.405  2740  8726 E SYNC-PUSH: 

com.xtc.sync.exception.DecodeException: decode data 

error:java.lang.ArrayIndexOutOfBoundsException: src.length=13 

srcPos=2 dst.length=67 dstPos=0 length=67
07-27 16:35:52.405  2740  8726 E SYNC-PUSH:     at 

com.xtc.sync.push.common.DataCoder.a(Unknown Source)
07-27 16:35:52.405  2740  8726 E SYNC-PUSH:     at 

com.xtc.sync.push.common.ConnectionService$6.onRead(Unknown 

Source)
07-27 16:35:52.405  2740  8726 E SYNC-PUSH:     at 

com.xtc.sync.push.common.ReadAndWriteDataThread.b(Unknown Source)
07-27 16:35:52.405  2740  8726 E SYNC-PUSH:     at 

com.xtc.sync.push.common.ReadAndWriteDataThread.a(Unknown Source)
07-27 16:35:52.405  2740  8726 E SYNC-PUSH:     at 

com.xtc.sync.push.common.ReadAndWriteDataThread.run(Unknown 

Source)

客戶端對接收到的TCP數據解析異常ArrayIndexOutOfBoundsException,數

組越界

07-27 16:35:54.479  2740  8737 E SYNC-PUSH: 

java.net.SocketException: Socket closed
07-27 16:35:54.479  2740  8737 E SYNC-PUSH:     at 

java.net.SocketInputStream.socketRead0(Native Method)
07-27 16:35:54.479  2740  8737 E SYNC-PUSH:     at 

java.net.SocketInputStream.read(SocketInputStream.java:151)
07-27 16:35:54.479  2740  8737 E SYNC-PUSH:     at 

java.net.SocketInputStream.read(SocketInputStream.java:120)
07-27 16:35:54.479  2740  8737 E SYNC-PUSH:     at 

java.net.SocketInputStream.read(SocketInputStream.java:106)
07-27 16:35:54.479  2740  8737 E SYNC-PUSH:     at 

com.xtc.sync.push.common.ReadAndWriteDataThread.run(Unknown 

Source)
07-27 16:35:54.480  2740  8737 I SYNC-PUSH: 

{ReadAndWriteDataThread.run--1} buffer size == 11,continue to 

read buffer...
07-27 16:35:54.480  2740  2753 D SYNC-PUSH: {ConnectionService

$ConnectionServiceBinder.a--1} enqueueSendTask:Binder:2740_2
07-27 16:35:54.480  2740  8737 W SYNC-PUSH: 

{ReadAndWriteDataThread.run--1} onInterrupt:false
07-27 16:35:54.481  2740  8737 D SYNC-PUSH: {TCPConnection

$1.onInterrupt--1} reconnect:false
07-27 16:35:54.481  2740  2753 D SYNC-PUSH: {TaskExecutor.a--1} 

execute a task,size:1
07-27 16:35:54.482  2740  8737 W SYNC-PUSH: {TCPConnection.u--1} 

connection is disconnected,connected time 

is:1501144554215,disconnected time is:1501144554481,connected 

time of duration is:266,minConnectPeriod format:00:00:01
07-27 16:35:54.482  2740  8737 W SYNC-PUSH: {ConnectionService

$5.onDisconnected--1} connection is disconnected
07-27 16:35:54.483  2740  8737 D SYNC-PUSH: {ConnectionService

$5.onDisconnected--1} on thread:Socket-Thread

客戶端在數據解析異常后斷線

07-27 16:35:52.623  2740  8726 I SYNC-PUSH: 

{WatchHearbeatScheduler.c--1} 失敗心跳向下探測達到極

值,heartbeatDetail:{"a":"CMCC-

4G","b":false,"c":240,"d":80,"e":0,"f":0,"g":240,"h":240,"i":1501

144552593,"j":[]}
07-27 16:35:52.625  2542  2739 D SYNC-PUSH: 

{ResponseDispatcher.a--1} timeout request,trigger a heartbeat 

request to test the connection...
07-27 16:35:52.627  2740  8726 I SYNC-PUSH: 

{WatchHearbeatScheduler.c--1} 失敗心跳調整結果,heartbeatDetail:

{"a":"CMCC-

4G","b":false,"c":240,"d":80,"e":0,"f":0,"g":240,"h":240,"i":1501

144552593,"j":[]}
07-27 16:35:52.627  2542  2739 W SYNC-PUSH: 

{TimeoutErrorHandler.a--1} timeout 

request:PublicKeyRequestEntity:{"RID":102914}
07-27 16:35:52.628  2740  8726 I SYNC-PUSH: 

{WatchHearbeatScheduler.d--1} after success is [false] 

adjusted,heartbeat.curHeart:240,networkTag:CMCC-4G

連接斷開后心跳下調

07-27 16:35:54.727  2740  2876 I SYNC-PUSH: {TCPConnection.a--1} 

connect時間間隔(ms):85
07-27 16:35:54.728  2740  2876 D SYNC-PUSH: {TaskExecutor.a--1} 

cancel task executor
07-27 16:35:54.729  2740  2876 I SYNC-PUSH: {TCPConnection.t--1} 

lastConnectPeriod:400
07-27 16:35:54.730  2740  2876 W SYNC-PUSH: {TCPConnection.t--1} 

connected and disconnected is too frequently,do not reset 

reconnectPeriodTag:120000
07-27 16:35:54.731  2740  2876 I SYNC-PUSH: {ConnectionService

$5.onConnected--1} connect to server 

success,hostname:gw.im.okii.com,port:80
07-27 16:35:54.732  2740  2876 D SYNC-PUSH: {ConnectionService

$5.onConnected--1} on thread:Task-Thread#1
07-27 16:35:54.733  2740  2876 D SYNC-PUSH: {TaskExecutor.d--1} 

start task executor
07-27 16:35:54.733  2740  5302 D SYNC-PUSH: {SendTask.j--1} 

execute the send task...
07-27 16:35:54.734  2740  5302 D SYNC-PUSH: 

{ConnectionService.c--1} sendOnBefore
07-27 16:35:54.735  2740  5302 I SYNC-PUSH: {ConnectionService

$6.onWrite--1} write [8] bytes.
07-27 16:35:54.735  2740  2876 I SYNC-PUSH: 

{AppUtil.isAppActive--1} com.xtc.i3launcher app is active
07-27 16:35:54.736  2740  2876 W ContextImpl: Calling a method in 

the system process without a qualified user: 

android.app.ContextImpl.startService:1357 

android.content.ContextWrapper.startService:613 

com.xtc.sync.push.common.HandleServiceNotify.a:-1 

com.xtc.sync.push.common.NotifyExecutor.a:-1 

com.xtc.sync.push.common.ConnectionService$5.onConnected:-1 
07-27 16:35:54.737  2740  5302 I SYNC-PUSH: 

{ConnectionService.e--1} remove a timeout request 

entity:PublicKeyRequestEntity:{"RID":102939},size:147
07-27 16:35:54.739  2740  5302 I SYNC-PUSH: 

{ConnectionService.e--1} remove a timeout request 

entity:PublicKeyRequestEntity:{"RID":102940},size:146
07-27 16:35:54.742  2740  2876 I SYNC-PUSH: 

{HandleServiceNotify.a--1} notify on push connected 

PushConnStatusChangedHandleServicesuccessfully,pkgName:com.xtc.i3

launcher
07-27 16:35:54.745  2740  5302 D SYNC-PUSH: 

{ConnectionService.b--1} data sent successfully.
07-27 16:35:54.745  2542  2542 D SYNC-PUSH: 

{BaseHandleService.onCreate--1} 

PushConnStatusChangedHandleService created...
07-27 16:35:54.746  2542  2542 I SYNC-PUSH: 

{BaseHandleService.onStartCommand--1} 

PushConnStatusChangedHandleService startId:1
07-27 16:35:54.747  2740  5302 I SYNC-PUSH: {SendTask.j--1} send 

data success,data:PublicKeyRequestEntity:{"RID":103141}
07-27 16:35:54.749  2740  5308 D SYNC-PUSH: {SendTask.j--1} 

execute the send task...
07-27 16:35:54.750  2740  5308 D SYNC-PUSH: 

{ConnectionService.c--1} sendOnBefore
07-27 16:35:54.750  2542  8743 D SYNC-PUSH: 

{BaseHandleService.onHandleIntent--1} 

PushConnStatusChangedHandleService onHandleIntent...
07-27 16:35:54.751  2542  8743 I SYNC-PUSH: 

{PushConnStatusChangedHandleService.a--1} receive 

action:com.xtc.sync.connected
07-27 16:35:54.751  2740  5308 I SYNC-PUSH: {ConnectionService

$6.onWrite--1} write [8] bytes.
07-27 16:35:54.752  2542  8743 I SYNC-PUSH: 

{PushConnStatusChangedHandleService$1.a--1} handle 

action:com.xtc.sync.connected
07-27 16:35:54.752  2542  8743 D SYNC-PUSH: 

{PushConnStatusChangedHandleService.b--1} handleSyncPushConnected
07-27 16:35:54.753  2542  8743 D SYNC-PUSH: 

{ConnectionServiceManager$7.c--1} execute hasPublicKey on aidl
07-27 16:35:54.754  2740  2753 D SYNC-PUSH: {ConnectionService

$ConnectionServiceBinder.k--1} hasPublicKey:Binder:2740_2
07-27 16:35:54.755  2740  5308 D SYNC-PUSH: 

{ConnectionService.b--1} data sent successfully.
07-27 16:35:54.756  2740  2876 I SYNC-PUSH: 

{NetUtil.getSIMType--1} getSIMType:46007,simOperatorName:CMCC
07-27 16:35:54.757  2740  2876 I SYNC-PUSH: 

{NetUtil.getSIMType--1} getSIMType:CMCC
07-27 16:35:54.757  2740  5308 I SYNC-PUSH: {SendTask.j--1} send 

data success,data:PublicKeyRequestEntity:{"RID":103142}
07-27 16:35:54.759  2740  5291 D SYNC-PUSH: {SendTask.j--1} 

execute the send task...
07-27 16:35:54.760  2740  5291 D SYNC-PUSH: 

{ConnectionService.c--1} sendOnBefore
07-27 16:35:54.760  2542  8743 D SYNC-PUSH: 

{RequestEntityFactory.createPublicKeyRequestEntity--1} create 

PublicKeyRequestEntity:PublicKeyRequestEntity:{"RID":103145}
07-27 16:35:54.761  2740  5291 I SYNC-PUSH: {ConnectionService

$6.onWrite--1} write [8] bytes.
07-27 16:35:54.761  2542  8743 D SYNC-PUSH: {RequestManager.a--1} 

add a request,RID:103145
07-27 16:35:54.763  2740  2876 I SYNC-PUSH: 

{NetUtil.getNetworkTag--1} Network tag:CMCC-4G
07-27 16:35:54.763  2740  5291 I SYNC-PUSH: 

{ConnectionService.e--1} remove a timeout request 

entity:PublicKeyRequestEntity:{"RID":102941},size:147
07-27 16:35:54.765  2542  8743 W SYNC-PUSH: {RequestSweeper.a--1} 

request sweeper is started.
07-27 16:35:54.766  1853  1863 V AlarmManager: set(PendingIntent

{ba4a156: PendingIntentRecord{6975513 com.xtc.i3launcher 

broadcastIntent}}) : type=0 triggerAtTime=1501144794765 win=0 

tElapsed=2996778 maxElapsed=2996778 interval=0 flags=0x9
07-27 16:35:54.767  2740  2876 I SYNC-PUSH: 

{WatchHearbeatScheduler.g--1} start heartbeat,curHeart 

[240],heart [240000],requestCode:83523235,stabled:false
07-27 16:35:54.770  2740  5291 D SYNC-PUSH: 

{ConnectionService.b--1} data sent successfully.
07-27 16:35:54.772  2740  5291 I SYNC-PUSH: {SendTask.j--1} send 

data success,data:PublicKeyRequestEntity:{"RID":103143}
07-27 16:35:54.773  2542  8743 D SYNC-PUSH: 

{ConnectionServiceManager$9.b--1} execute enqueueSendTask on aidl
07-27 16:35:54.774  2740  5293 D SYNC-PUSH: {SendTask.j--1} 

execute the send task...
07-27 16:35:54.775  2740  5293 D SYNC-PUSH: 

{ConnectionService.c--1} sendOnBefore
07-27 16:35:54.775  2542  8743 I SYNC-PUSH: 

{ConnectionServiceManager$9.b--1} enqueue request 

entity:PublicKeyRequestEntity:{"RID":103145}
07-27 16:35:54.776  2740  5293 I SYNC-PUSH: {ConnectionService

$6.onWrite--1} write [8] bytes.
07-27 16:35:54.777  2740  2752 D SYNC-PUSH: {ConnectionService

$ConnectionServiceBinder.a--1} enqueueSendTask:Binder:2740_1
07-27 16:35:54.778  2740  2876 I SYNC-PUSH: 

{NetUtil.getSIMType--1} getSIMType:46007,simOperatorName:CMCC
07-27 16:35:54.779  2740  5293 D SYNC-PUSH: 

{ConnectionService.b--1} data sent successfully.
07-27 16:35:54.780  2740  2752 D SYNC-PUSH: {TaskExecutor.a--1} 

execute a task,size:1
07-27 16:35:54.781  2740  2876 I SYNC-PUSH: 

{NetUtil.getSIMType--1} getSIMType:CMCC
07-27 16:35:54.782  2740  5293 I SYNC-PUSH: {SendTask.j--1} send 

data success,data:PublicKeyRequestEntity:{"RID":103144}
07-27 16:35:54.783  2542  8743 D SYNC-PUSH: {AIDLHelper.d--1} run 

aidl task...
07-27 16:35:54.784  2740  5313 D SYNC-PUSH: {SendTask.j--1} 

execute the send task...
07-27 16:35:54.784  2740  5313 D SYNC-PUSH: 

{ConnectionService.c--1} sendOnBefore
07-27 16:35:54.786  2740  5313 I SYNC-PUSH: {ConnectionService

$6.onWrite--1} write [8] bytes.
07-27 16:35:54.787  2740  2876 I SYNC-PUSH: 

{NetUtil.getNetworkTag--1} Network tag:CMCC-4G
07-27 16:35:54.788  2542  2542 D SYNC-PUSH: 

{BaseHandleService.onDestroy--1} 

PushConnStatusChangedHandleService destroy...
07-27 16:35:54.793  2740  2876 I SYNC-PUSH: 

{WatchHearbeatScheduler.a--1} start heartbeat,networkTag:CMCC-4G
07-27 16:35:54.799  2740  5313 D SYNC-PUSH: 

{ConnectionService.b--1} data sent successfully.
07-27 16:35:54.800  2740  5313 I SYNC-PUSH: {SendTask.j--1} send 

data success,data:PublicKeyRequestEntity:{"RID":103145}
07-27 16:35:54.816  2740  2876 I SYNC-PUSH: {ConnectionService

$5.onConnected--1} 預埋IP信息:

[{"connectCount":19,"connectFailedCount":19,"connectedSuccessCoun

t":0,"disconnectedCount":0,"dns":false,"hostname":"gw.im.okii.com

","lastConnectFailedCount":19,"port":8000,"start":1501141844507,"

ttl":0,"update":1501144081255}, 

{"connectCount":682,"connectFailedCount":1,"connectedSuccessCount

":680,"disconnectedCount":680,"dns":false,"hostname":"gw.im.okii.

com","lastConnectFailedCount":0,"port":80,"start":1501141844632,"

ttl":0,"update":1501144554639}, 

{"connectCount":0,"connectFailedCount":0,"connectedSuccessCount":

0,"disconnectedCount":0,"dns":false,"hostname":"120.25.129.142","

lastConnectFailedCount":0,"port":1883,"start":1501141844602,"ttl"

:0,"update":0}, 

{"connectCount":0,"connectFailedCount":0,"connectedSuccessCount":

0,"disconnectedCount":0,"dns":false,"hostname":"120.25.129.142","

lastConnectFailedCount":0,"port":8000,"start":1501141844614,"ttl"

:0,"update":0}]
07-27 16:35:54.822  2740  2876 I SYNC-PUSH: 

{NetUtil.getSIMType--1} getSIMType:46007,simOperatorName:CMCC
07-27 16:35:54.823  2740  2876 I SYNC-PUSH: 

{NetUtil.getSIMType--1} getSIMType:CMCC
07-27 16:35:54.826  2740  2876 I SYNC-PUSH: 

{NetUtil.getNetworkTag--1} Network tag:CMCC-4G
07-27 16:35:54.827  2740  2876 D SYNC-PUSH: {DataCollector.a--1} 

record push socket info
07-27 16:35:54.828  2740  2876 I SYNC-PUSH: {TCPConnection.a--1} 

connect to server success 

{remoteAddress=gw.im.okii.com,remotePort=80}

客戶端在不切換域名和端口的情況下斷線重連成功

解決方案

  • 客戶端禁止使用80端口
  • 針對以上香港問題分析出的客戶端在心跳下調策略,重連策略存在的缺

陷進行修復(主要是在重連的時候要確保域名或者端口的切換,不要拿舊

的域名和端口再次嘗試連接)

解決效果

  • 青海域名劫持問題,TCP連接80端口可以成功,但是不確定8000端口是否

能成功,如果8000端口無法連接成功,那么1.0.4Release或以上版本(去

掉80端口)程序在遇到域名被劫持的時候,再次嘗試連接不成功,這時候

就會去跑常規的httpdns流程

  • 新修改的IM的Httpdns方案無論是否使用80端口,都可以解決劫持的

問題,目前并沒有在1.0.+Release版本的程序更新,是在當前手表主干更

新的,目前還在提測階段

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 228,238評論 6 531
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 98,430評論 3 415
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 176,134評論 0 373
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,893評論 1 309
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 71,653評論 6 408
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 55,136評論 1 323
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,212評論 3 441
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 42,372評論 0 288
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 48,888評論 1 334
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 40,738評論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 42,939評論 1 369
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,482評論 5 359
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,179評論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,588評論 0 26
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,829評論 1 283
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 51,610評論 3 391
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 47,916評論 2 372

推薦閱讀更多精彩內容

  • 主目錄見:Android高級進階知識(這是總目錄索引)[written by 無心追求] 心跳異常 香港心跳異常 ...
    ZJ_Rocky閱讀 1,436評論 0 3
  • 個人認為,Goodboy1881先生的TCP /IP 協議詳解學習博客系列博客是一部非常精彩的學習筆記,這雖然只是...
    貳零壹柒_fc10閱讀 5,079評論 0 8
  • 1.這篇文章不是本人原創的,只是個人為了對這部分知識做一個整理和系統的輸出而編輯成的,在此鄭重地向本文所引用文章的...
    SOMCENT閱讀 13,107評論 6 174
  • 名詞延伸 通俗的說,域名就相當于一個家庭的門牌號碼,別人通過這個號碼可以很容易的找到你。如果把IP地址比作一間房子...
    楊大蝦閱讀 20,616評論 2 56
  • Spring Cloud為開發人員提供了快速構建分布式系統中一些常見模式的工具(例如配置管理,服務發現,斷路器,智...
    卡卡羅2017閱讀 134,781評論 18 139