Tcp 连接挂在 CLOSE_WAIT 状态
客户端首先关闭套接字,当服务器没有太多数据时,tcp连接关闭是可以的,例如:
FIN -->
<-- ACK
<-- FIN, ACK
ACK -->
当服务器正忙于发送数据时:
FIN -->
<-- ACK,PSH
RST -->
服务器连接进入CLOSE_WAIT状态并长时间挂起。
这里有什么问题?客户端相关还是服务器相关? Redhat5 上的本地套接字会发生这种情况。
这文章讲了为什么发送“RST”,但是不知道为什么服务器连接卡在CLOSE_WAIT,并且不发送FIN出去。
[编辑]我忽略了最重要的信息,这发生在 qemu 的 slirp 网络仿真上。这似乎是处理紧密连接的 slirp bug 的问题。
Client close the socket first, when there is not much data from server, tcp connection shutdown is okay like:
FIN -->
<-- ACK
<-- FIN, ACK
ACK -->
When the server is busying sending data:
FIN -->
<-- ACK,PSH
RST -->
And the server connection comes to CLOSE_WAIT state and hang on there for a long time.
What's the problem here? client related or server related? This happens on Redhat5 for local sockets.
This article talk about why "RST" is sent, but I do not know why the server connection stuck on CLOSE_WAIT, and do not send a FIN out.
[EDIT]I ignored the most important information, this happens on qemu's slirp network emulation. It seems to be a problem of slirp bug for dealing with close connection.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这意味着流中还有未读的数据,即客户端尚未完成读取。
您可以使用
SO_LINGER
选项强制关闭它。 这里是 Linux 的相关文档(另请参阅选项本身,这里),以及 Win32 的[这里是匹配函数2]。服务器端保持打开状态,因此您可以尝试在服务器端禁用
SO_LINGER
。This means that there is unread data left in in the stream, that the client hasn't finished reading.
You can force it off by using the
SO_LINGER
option. Here's relevant documentation for Linux (also see the option itself, here), and [here's the matching function2] for Win32.It's the server side that is remaining open, so it's on the server side you can try disabling
SO_LINGER
.这可能意味着服务器尚未关闭套接字。您可以通过使用“lsof”列出该进程打开的文件描述符(其中包括 TCP 套接字)来轻松判断这一点。解决方法是让进程在完成时始终关闭套接字(即使在错误情况下等)
It may mean that the server hasn't closed the socket. You can easily tell this by using "lsof" to list the file descriptors open by that process which will include TCP sockets. The fix is to have the process always close the socket when it's finished (even in error cases etc)
这是已知的qemu 的缺陷。
This a known defect for qemu.