Today, a Linux server has been reporting the exception of too Many Open files, causing the system to fail the network request, restart the application container and return to normal.
Found the server connection monitoring at that time, found that the close_wait state of the connection has been elevated, up to 10k after the application of the error. Because the maximum number of connections we set for Linux is 10240.
Stroll around the blog park and find the following description
If our server TCP connection is in the close_wait state, it means that the socket is closed passively!
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/
Because if the client side takes the initiative to disconnect the current connection, then both sides will need four packet to close the TCP connection:
Client---> FIN---> Server
Client <---ACK <---Server
The client side is in the fin_wait_2 state, and the server program is in the Close_wait state.
Client <---FIN <---Server
The Server sends the fin to the client,server to be placed in the Last_ack state.
Client---> ACK---> Server (This step is not done)
The client responds to the ACK, then the server's socket is actually placed in the closed state.
The Server program is in a close_wait state, not a last_ack state, indicating that the fin has not been sent to the client, so there may be a lot of data to send or something else to do before closing the connection, causing the fin packet to not be sent.
Usually, a close_wait will last for at least 2 hours.
Understand this situation, can be positioned to apply the reason why so many close_wait state, is because the receiver has been sent over the notice, is a partner in the notification after sending the ACK response to us, resulting in a close_wait state backlog, The maximum number of system settings is exceeded and no more connections can be established.
Shorten this time by modifying the parameters of TCP/IP: Modifying the tcp_keepalive_* series parameters helps solve this problem.
Author: Cnblogs Week tadpole