开发者

Strange network socket leak in Java app

I'm trying to catch a network socket leak in our Java daemon, which has quite a strange output in lsof:

java    11734 root  463u  IPv6          225927527                TCP 192.168.254.1:http->192.168.254.1:46149 (CLOSE_WAIT)
java    11734 root  464u  IPv6          225927347                TCP 192.168.254.1:http->192.168.254.1:46102 (CLOSE_WAIT)
java    11734 root  465u  IPv6          225928791                TCP 192.168.254.1:http->192.168.254.1:46451 (CLOSE_WAIT)
java    11734 root  466u  IPv6          225927617            开发者_运维技巧    TCP 192.168.254.1:http->192.168.254.1:46170 (CLOSE_WAIT)
java    11734 root  467u  IPv6          225930330                TCP 192.168.254.1:http->192.168.254.1:57333 (CLOSE_WAIT) 

And so on, until it eats all the available descriptors and leads to "Too many files" error.

Any idea what can cause this?

Thanks in advance!


CLOSE_WAIT means that the connection has been closed by the remote peer but the socket is waiting for the local application to close it. So you're not doing that.

You need to check that you handle EOS properly, i.e. by closing the socket, under all circumstances where it can arise, and ditto IOExceptions on any socket operation - you must respond to all of them except SocketTimeoutException by closing the socket. You must also ensure sockets are closed in finally blocks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜