1. 程式人生 > >Java SDK夯住(Hang)問題排查

Java SDK夯住(Hang)問題排查

access rem 發現 write 情況 nag opera spa waiting

夯住(Hang)是指程序仍在運行,卡在某個方法調用上,沒有返回也沒有異常拋出;卡住時間從幾秒到幾小時不等。 Java程序發生Hang時,應該首先使用 jstack 把java進程的堆棧信息保存下來 ,供後繼分析使用。

調用OSS Java SDK的程序Hang,有以下可能的情況及原因。

技術分享圖片

說明:

  • jstack -l <pid> > js.txt可以把pid的堆棧信息保存到文件js.txt中。pid可以通過jps命令查找到。
  • 抓包工具,Windows系統下推薦使用Wireshark。捕獲篩選器可以設置成
    host <bucket-name>.<endpoint>
    ,例如:
host my-bucket.oss-cn-hangzhou.aliyuncs.com`

Linux使用tcpdump命令抓包,命令格式如下:

sudo tcpdump tcp -i <eth0> -t -s 0 -c 200000 and host <bucket>.<endpoint> -w <file.cap>

例如:

sudo tcpdump tcp -i eth0 -t -s 0 -c 200000 and host my-bucket.oss-cn-hangzhou.aliyuncs.com -w out.cap`

然後用Wireshark打開file.cap分析抓包數據。

  • getObject獲取的InputStream需要close,示例如下:
OSSObject ossObject = ossClient.getObject(bucketName, key);
ossObject.getObjectContent().close();
  • OSS Java SDK 2.2.3前的版本getSimplifiedObjectMeta調用有bug,連接沒有關閉,會造成泄漏。2.2.3版本修復。
  • hang在PoolingHttpClientConnectionManager.leaseConnection的堆棧如下:
"main" prio=6 tid=0x000000000291e000 nid=0xc40 waiting on condition [0x0000000002dae000]
java.lang.Thread.State: WAITING (parking)
    at sun.misc.Unsafe.park(Native Method)
    - parking to wait for  <0x00000007d85697f8> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
    at org.apache.http.pool.PoolEntryFuture.await(PoolEntryFuture.java:138)
    at org.apache.http.pool.AbstractConnPool.getPoolEntryBlocking(AbstractConnPool.java:306)
    at org.apache.http.pool.AbstractConnPool.access$000(AbstractConnPool.java:64)
    at org.apache.http.pool.AbstractConnPool$2.getPoolEntry(AbstractConnPool.java:192)
    at org.apache.http.pool.AbstractConnPool$2.getPoolEntry(AbstractConnPool.java:185)
    at org.apache.http.pool.PoolEntryFuture.get(PoolEntryFuture.java:107)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.leaseConnection(PoolingHttpClientConnectionManager.java:276)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$1.get(PoolingHttpClientConnectionManager.java:263)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:190)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
    at com.aliyun.oss.common.comm.DefaultServiceClient.sendRequestCore(DefaultServiceClient.java:113)
    at com.aliyun.oss.common.comm.ServiceClient.sendRequestImpl(ServiceClient.java:123)
    at com.aliyun.oss.common.comm.ServiceClient.sendRequest(ServiceClient.java:68)
    at com.aliyun.oss.internal.OSSOperation.send(OSSOperation.java:94)
    at com.aliyun.oss.internal.OSSOperation.doOperation(OSSOperation.java:146)
    at com.aliyun.oss.internal.OSSOperation.doOperation(OSSOperation.java:113)
    at com.aliyun.oss.internal.OSSObjectOperation.getObject(OSSObjectOperation.java:229)
    at com.aliyun.oss.OSSClient.getObject(OSSClient.java:629)
    at com.aliyun.oss.OSSClient.getObject(OSSClient.java:617)
    at samples.HelloOSS.main(HelloOSS.java:49)
  • hang在java.net.SocketOutputStream.socketWrite的堆棧如下:
"main" prio=10 tid=0x0000000040112800 nid=0x2ad8 runnable [0x00000000418e1000]
   java.lang.Thread.State: RUNNABLE
        at java.net.SocketOutputStream.socketWrite0(Native Method)
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
        at org.apache.http.impl.conn.LoggingOutputStream.write(LoggingOutputStream.java:77)
        at org.apache.http.impl.io.SessionOutputBufferImpl.streamWrite(SessionOutputBufferImpl.java:126)
        at org.apache.http.impl.io.SessionOutputBufferImpl.flushBuffer(SessionOutputBufferImpl.java:138)
        at org.apache.http.impl.io.SessionOutputBufferImpl.write(SessionOutputBufferImpl.java:169)
        at org.apache.http.impl.io.ContentLengthOutputStream.write(ContentLengthOutputStream.java:115)
        at com.aliyun.oss.common.comm.RepeatableInputStreamEntity$NoAutoClosedInputStreamEntity.writeTo(RepeatableInputStreamEntity.java:127)
        at com.aliyun.oss.common.comm.RepeatableInputStreamEntity.writeTo(RepeatableInputStreamEntity.java:71)
        at org.apache.http.impl.DefaultBHttpClientConnection.sendRequestEntity(DefaultBHttpClientConnection.java:158)
        at org.apache.http.impl.conn.CPoolProxy.sendRequestEntity(CPoolProxy.java:162)
        at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:237)
        at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:122)
        at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:271)
        at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
        at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
        at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
        at com.aliyun.oss.common.comm.DefaultServiceClient.sendRequestCore(DefaultServiceClient.java:113)
        at com.aliyun.oss.common.comm.ServiceClient.sendRequestImpl(ServiceClient.java:121)
        at com.aliyun.oss.common.comm.ServiceClient.sendRequest(ServiceClient.java:67)
        at com.aliyun.oss.internal.OSSOperation.send(OSSOperation.java:92)
        at com.aliyun.oss.internal.OSSOperation.doOperation(OSSOperation.java:140)
        at com.aliyun.oss.internal.OSSOperation.doOperation(OSSOperation.java:111)
        at com.aliyun.oss.internal.OSSObjectOperation.writeObjectInternal(OSSObjectOperation.java:665)
        at com.aliyun.oss.internal.OSSObjectOperation.putObject(OSSObjectOperation.java:132)
        at com.aliyun.oss.OSSClient.putObject(OSSClient.java:528)
        at com.aliyun.oss.OSSClient.putObject(OSSClient.java:516)
        at com.aliyun.oss.OSSClient.putObject(OSSClient.java:522)
        at com.aliyun.oss.demo.HelloOSS.main(HelloOSS.java:25)
本文為雲棲社區原創內容,未經允許不得轉載,如需轉載請發送郵件至[email protected]
如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至:[email protected] 進行舉報,並提供相關證據,一經查實,本社區將立刻刪除涉嫌侵權內容。

https://yq.aliyun.com/articles/61325?spm=a2c4g.11186623.2.34.631b54130pevRE

Java SDK夯住(Hang)問題排查