Open gabeblack opened 10 months ago
Do you want to fix this bug?
no, sorry. -- Found just invoking ssh -fN
is a much better solution. I had forgotten that ssh client itself has very good tunnel 'daemon' support.
I contribute to projects on occasion and have to pick my battles.
@gabeblack Thanks for pointing that alternative out. I packaged ssh_tunnel in the hopes of abstracting the process for others, but because my deployment environment does not need an ssh tunnel, it's probably better if I remove it altogether.
I think I have pretty up-to-date versions installed:
I have tried with both
open_tunnel
andSSHTunnelForwarder
. If one opens a tunnel and the tunnel throws an exception (e.g., the remote doesn't have the ssh_key installed), it seems impossible to get the tunnel to fully clean up all its resources. Even if one allows open_tunnel to go out of scope (or by callingstop()
on theSSHTunnelForwarder
), the local sockets that are listening for tunnel connections are not closed. Thus a subsequent attempt to open a new tunnel fails because the port is already in use. Actually, in the case of SSHTunnelForwarder, a call toclose()
hangs indefinitely (even if you pass inforce=True
).Here is a simple example demonstrating the problem.
When running
netstat -apn | grep 2345
. You will get:indicating that the python program is still listening on port
2345
, even though at that point in the program the context manager for open_tunnel has already closed and the server and sockets should have been cleaned up.