How to get to know when remote host is down in SSH?

69 views Asked by At

When using OpenSSH from command line, we can use -o ServerAliveInterval=30 -o ServerAliveCountMax=2 to timeout the command if server do not respond to keepalive packets.

Similary, when using ssh2-python in blocking mode, which is based on libssh2, it is sufficient to set session.keepalive_config(_, 60) for similar behaviour.

But when using the same library in non-blocking mode, this won't work. All of the channel functions, including wait_eof, return LIBSSH2_ERROR_EAGAIN. So, if connection is lost in between, these functions will wait forever and never exit. How to avoid this?

0

There are 0 answers