Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ObjectOutputStream getting struck

A thread, which is responsible for writing on a socket (huge amount of data,around 4-5MBPS) is getting stuck, sometimes for as long as 15 minutes, and then comes to action again and then is getting stuck again with part stack trace as:

 java.lang.Thread.State: RUNNABLE
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(Unknown Source)
    at java.net.SocketOutputStream.write(Unknown Source)
    at java.io.BufferedOutputStream.write(Unknown Source)
    - locked <0xa4ca4660> (a java.io.BufferedOutputStream)
    mypackage.myMethod()

My immediate assumption was ObjectWrite is getting block.But this behavior is erratic at best. Underlying network seems okay. It has been writing successfully for hours before getting stuck.

Thread also takes rest of at least 50ms before writing next chunk. So if it is not normal block, what else it could be?

pstack:

ff2cba60 send     (10, 4dc230, c312, 0)
fe03ce58 Java_java_net_SocketOutputStream_socketWrite0 (3a4928, c312, 10, 95f7f890, 0, c312) + 158
fc093e5c * java/lang/System.getSecurityManager()Ljava/lang/SecurityManager;+3
fc08ec3c * *java/net/SocketOutputStream.socketWrite([BII)V [compiled] +45
fc08ec3c * *java/net/SocketOutputStream.write([BII)V+5
fc005ab0 * java/io/BufferedOutputStream.write([BII)V+20
fc005ab0 * mypackage.mymethod()V+84 (line 598)
like image 500
mawia Avatar asked Oct 22 '22 12:10

mawia


1 Answers

I suspect the problem is your server isn't reading fast enough so the TCP send buffer fills up. TCP has algorithms to help it figure when to send data packets and it is largely based on the current state of the transfer. So if the TCP stack detects a congestion (because you're sending large amount of data and the server isn't keeping up). It'll slow down/pause. Read this for more info.

I don't have a readily answer on what exactly to fix because all you shared is a stack trace, but if I were you, I'd look at the server rather than the client in this case.

like image 154
mprivat Avatar answered Oct 27 '22 20:10

mprivat