Apache hangs after every 2-3 weeks, with closed_wait connections increasing until it is restarted
Solution 1:
This is a common issue. CLOSE_WAIT connections are not being used but consuming apache resources.
I faced the Close wait connections problem some time ago. And after a lot of investigation here is the trick in case you need it.
You will need to add this to your Linux server
vi /etc/sysctl.conf
#Added to fix close_wait connections
#recommended 30. Default 60
net.ipv4.tcp_fin_timeout = 30
#in seconds, time in which the close_wait connections will be removed
net.ipv4.tcp_keepalive_time = 60
###duration of a request in seconds# probes * intvl = time to process if the connection is still alive
net.ipv4.tcp_keepalive_intvl = 2
#number of retries to test the connection
net.ipv4.tcp_keepalive_probes = 2
Also, after applying this you need to refresh the references to that file using sysctl -p command.
After that, you have to add the keepalive=On directive in your proxy pass.
ProxyPass /home ajp://localhost:8009/home keepalive=On retry=5
This will help to remove the close_wait connections after a minute of being in CLOSE_WAIT state. Apache uses threads in the worker mode, and those threads are handled by the OS, if the system is not able to close it, the system will do.
Remember to restart the whole apache process too.
PD: This helps if you are using ipv4. Not sure about ipv6
Hope it helps