如何删除CLOSE_WAIT套接字连接?

时间:2021-03-29 23:56:03

I have write a simple program using socket in C that create a connect between X86 running windows and ARM running embedded linux(consist of only Busybox and libc).Suddenly this small program could not connect the windows and linux,then I running "netsta -a" found 3 socket's state is CLOSE_WAIT and PID is NULL.So I try to modify “net.ipv4.tcp_keepalive_×” but because busybox has only the basic functions that I could not using /etc/rc.d/init.d/network restart makes the modify take effect.

我在C中使用socket编写了一个简单的程序,它在X86运行窗口和运行嵌入式linux的ARM之间建立连接(仅包含Busybox和libc)。突然这个小程序无法连接windows和linux,然后我运行“netsta - “找到3个套接字的状态是CLOSE_WAIT,PID是NULL。所以我尝试修改”net.ipv4.tcp_keepalive_ד,但因为busybox只有我无法使用的基本功能/etc/rc.d/init.d/网络重启使修改生效。

So I want to know:

所以我想知道:

  1. how to make the change take effect with Busybox?
  2. 如何使更改生效与Busybox?
  3. how I using socket can avoid the CLOSE_WAIT problem?
  4. 我如何使用socket可以避免CLOSE_WAIT问题?

2 个解决方案

#1


1  

How do I remove a CLOSE_WAIT connection that doesn't belong to any tasks?

如何删除不属于任何任务的CLOSE_WAIT连接?

As we've established that the process is still running, it does belong to a task. We've also established that the netstat output was a complete red herring.

由于我们已经确定该进程仍在运行,因此它确实属于任务。我们还确定netstat输出是一个完整的红鲱鱼。

All you have to do is close the socket. You probably forget to close it after you got the connection failure. It's just a common or garden file/socket descriptor leak.

您所要做的就是关闭套接字。在连接失败后,您可能忘记关闭它。它只是一个常见的或花园文件/套接字描述符泄漏。

#2


0  

You might want to check out: https://github.com/rghose/kill-close-wait-connections

您可能需要查看:https://github.com/rghose/kill-close-wait-connections

What this script does is send out the ACK which the connection was waiting for.

这个脚本的作用是发送连接等待的ACK。

This is what worked for me.

这对我有用。

#1


1  

How do I remove a CLOSE_WAIT connection that doesn't belong to any tasks?

如何删除不属于任何任务的CLOSE_WAIT连接?

As we've established that the process is still running, it does belong to a task. We've also established that the netstat output was a complete red herring.

由于我们已经确定该进程仍在运行,因此它确实属于任务。我们还确定netstat输出是一个完整的红鲱鱼。

All you have to do is close the socket. You probably forget to close it after you got the connection failure. It's just a common or garden file/socket descriptor leak.

您所要做的就是关闭套接字。在连接失败后,您可能忘记关闭它。它只是一个常见的或花园文件/套接字描述符泄漏。

#2


0  

You might want to check out: https://github.com/rghose/kill-close-wait-connections

您可能需要查看:https://github.com/rghose/kill-close-wait-connections

What this script does is send out the ACK which the connection was waiting for.

这个脚本的作用是发送连接等待的ACK。

This is what worked for me.

这对我有用。