I've set up a tunnel successfully between two servers, such that incoming connections on port 80/443 are forwarded to another server that is actually running the webserver. Further, I've used autossh to maintain the connection.
This works great, except that instead of closing fully, many of the incoming connections end up in a state of FIN_WAIT2:
sample netstat output
..and since they are associated with a running process, they are never cleaned up by the system. Eventually, I hit the open files limit, resulting in the SSH client accepting no new connections. The problem is, I can't figure out why this is happening. Many of the incoming connections close cleanly, but others just persist infinitely.
Things I've tried:
Disabling ServerAliveInterval/CountMax, ClientAliveInterval/CountMax, and TCPkeepAlive
Restarting the service (works, but isn't really a solution)
The research I've done into this leads me to very few sources of information, such as
this question on serverfault, which haven't offered any solution.
I don't understand how connections that aren't kept alive and from which the client has disconnected remain active. Can anyone shed some light?