From 892153b3d97cf5c77f4de115ed870b4ea319ce84 Mon Sep 17 00:00:00 2001 From: AndyPC <59114493+APCBoston@users.noreply.github.com> Date: Thu, 31 Oct 2024 11:26:16 -0400 Subject: [PATCH] Adds a timeout to the SSH channel. (#45) This resolves an issue in which a channel.recv() operation can hang when the host's sshd is alive but netconfd has hung or fallen over. The TCP socket and Paramiko Transport do not time out because data is still flowing, but the NETCONF connection hangs. We have observed a simple NETCONF HELLO exchange to hang for over 2.5 hours in the wild despite the socket timeout being set. Paramiko channels, it turns out, have their own timeout that is independdent of the socket/transport timeout. --- netconf_client/connect.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/netconf_client/connect.py b/netconf_client/connect.py index 06a4df2..726a520 100644 --- a/netconf_client/connect.py +++ b/netconf_client/connect.py @@ -60,7 +60,7 @@ 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() + channel = transport.open_session(timeout=general_timeout) except Exception: transport.close() raise diff --git a/pyproject.toml b/pyproject.toml index d2d91f3..7106689 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "netconf_client" -version = "3.1.1" +version = "3.1.2" description = "A Python NETCONF client" authors = ["ADTRAN, Inc."] license = "Apache-2.0"