Skip to content

Commit 53c4c4e

Browse files
justin-stephensonpbrezina
authored andcommitted
ssh: workaround timeout issue with SSH_AUTH_AGAIN
When the timeout is set to 1 in LibsshSession(timeout=1), libssh returns SSH_AUTH_AGAIN but pylibssh does not handle SSH_AUTH_AGAIN and therefore no exception is raised here: with pytest.raises(SSHAuthenticationError): client.ssh("user1", "Wrong").connect() Setting the timeout to 1 is necessary to allow the timeout set in client.host.conn.run(..., timeout=X) to work as expected. This is due to code becoming blocked in libssh which is C not Python, but the Python signal is delayed until we get back to the Python code
1 parent 9d8c93d commit 53c4c4e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

pytest_mh/conn/ssh.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ def __init__(
454454
# since Python will not deliver signal if the code is blocked in C
455455
# library. The signal is deliver only after we get back to the Python
456456
# code.
457-
self.__conn: LibsshSession = LibsshSession(timeout=1)
457+
self.__conn: LibsshSession = LibsshSession()
458458

459459
def _read_private_key(
460460
self,
@@ -518,6 +518,7 @@ def connect(self) -> None:
518518
port=self.port,
519519
host_key_checking=False,
520520
)
521+
self.__conn.set_ssh_options("timeout", 1)
521522
except LibsshSessionException as e:
522523
raise SSHAuthenticationError(self.host, self.port, self.user, e.message)
523524

0 commit comments

Comments
 (0)