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?