I'm using paramiko
for SSH connection with server. exec_command
always hangs forever if server becomes unavailable (for example unexpectedly turned off) and timeout doesn't actually work.
I also tried set_keepalive
, but it doesn't work either. As far as I understood from source codes keepalive is implemented for server. It just sends something to the server periodically to keep connection alive, but doesn't check for any read timeout on the client side.
Is there any way to handle unexpected connection drops? Maybe you can suggest something better then paramiko
or the way I can fix it?
I also tried to set TCP level keep alive, but it doesn't help much.
sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPIDLE, 10)
sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPINTVL, 10)
sock.setsockopt(socket.SOL_TCP, socket.TCP_KEEPCNT, 3)