From 32a3d33ca1c2d385954304a7a87186f574c780cc Mon Sep 17 00:00:00 2001 From: vakarisz Date: Tue, 22 Mar 2022 12:10:38 +0200 Subject: Add timeout for opening an SSH channel --- paramiko/client.py | 5 +++++ paramiko/transport.py | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/paramiko/client.py b/paramiko/client.py index 5667d7e7..a9e4e233 100644 --- a/paramiko/client.py +++ b/paramiko/client.py @@ -233,6 +233,7 @@ class SSHClient(ClosingContextManager): gss_host=None, banner_timeout=None, auth_timeout=None, + channel_timeout=None, gss_trust_dns=True, passphrase=None, disabled_algorithms=None, @@ -311,6 +312,8 @@ class SSHClient(ClosingContextManager): for the SSH banner to be presented. :param float auth_timeout: an optional timeout (in seconds) to wait for an authentication response. + :param float channel_timeout: an optional timeout (in seconds) to wait + for a channel open response. :param dict disabled_algorithms: an optional dict passed directly to `.Transport` and its keyword argument of the same name. @@ -401,6 +404,8 @@ class SSHClient(ClosingContextManager): t.banner_timeout = banner_timeout if auth_timeout is not None: t.auth_timeout = auth_timeout + if channel_timeout is not None: + t.channel_timeout = channel_timeout if port == SSH_PORT: server_hostkey_name = hostname diff --git a/paramiko/transport.py b/paramiko/transport.py index 2b6acd6e..0c6c3ad1 100644 --- a/paramiko/transport.py +++ b/paramiko/transport.py @@ -516,6 +516,8 @@ class Transport(threading.Thread, ClosingContextManager): self.handshake_timeout = 15 # how long (seconds) to wait for the auth response. self.auth_timeout = 30 + # how long (seconds) to wait for opening a channel + self.channel_timeout = 60 * 60 self.disabled_algorithms = disabled_algorithms or {} self.server_sig_algs = server_sig_algs @@ -1015,7 +1017,7 @@ class Transport(threading.Thread, ClosingContextManager): """ if not self.active: raise SSHException("SSH session not active") - timeout = 3600 if timeout is None else timeout + timeout = self.channel_timeout if timeout is None else timeout self.lock.acquire() try: window_size = self._sanitize_window_size(window_size) -- cgit v1.2.1