I'm doing a lot of reverse forwarding and ran into a situation in which I thought I was leaking sockets. If you do a reverse forward and then just keep connecting and disconnecting to the port the number of open sockets just keeps going up.
What I figured out is that it's not really going up it just takes awhile to close. If you connect to the port every 5 seconds it will level off at a couple hundred. The ssh server sends a channel eof but the socket doesn't get released until some other thread comes along that seems to clean up sessions. I don't fully understand the details of that. What I've done to work around this issue is just close the sockets on channel eof. I'm not really sure if that is a generally safe change, but it is working for my use case. I'm not sure what a proper fix would be or even if this is consider a bug, but the end result of the behavior is that reverse forwarding is not useful when you expect to have connections happening regularly. You will quickly run out of FDs. Darren
