Java 应用程序中奇怪的网络套接字泄漏

发布于 2024-10-08 08:15:47 字数 783 浏览 2 评论 0原文

我试图在我们的 Java 守护程序中捕获网络套接字泄漏,该守护程序在 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) 

等等,直到它吃掉所有可用的描述符并导致“文件过多”错误。

知道什么会导致这种情况吗?

提前致谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梅窗月明清似水 2024-10-15 08:15:47

CLOSE_WAIT 表示连接已被远程对等方关闭,但套接字正在等待本地应用程序将其关闭。所以你没有这样做。

您需要检查您是否正确处理 EOS,即在所有可能出现的情况下关闭套接字,并且在任何套接字操作上的 IOExceptions 也是如此 - 您必须响应所有 通过关闭套接字,除了 SocketTimeoutException 之外。您还必须确保套接字在finally 块中关闭。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文