Skip to content

Commit

Permalink
More Fun with Timeouts (#46)
Browse files Browse the repository at this point in the history
Fixes timeouts in transport.open_session() to account
for paramiko's behavior of always opening the channel in blocking mode,
only applying the timeout kwarg to the initial connection.
  • Loading branch information
APCBoston authored Dec 9, 2024
1 parent 892153b commit ce96160
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion netconf_client/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ def connect_ssh(
hostkey = _try_load_hostkey_b64(hostkey_b64) if hostkey_b64 else None
transport.connect(username=username, password=password, pkey=pkey)
try:
channel = transport.open_session(timeout=general_timeout)
# Paramiko always opens the channel in blocking mode, even when a timeout is specified. See https://github.com/paramiko/paramiko/blob/23f92003898b060df0e2b8b1d889455264e63a3e/paramiko/channel.py#L612-L633
# This means that even if the Transport is holding a non-blocking socket, and the channel is created with a timeout, a channel.read() call can still hang if the remote misbehaves.
channel = transport.open_session(timeout=initial_timeout)
channel.settimeout(general_timeout)
except Exception:
transport.close()
raise
Expand Down

0 comments on commit ce96160

Please # to comment.