From aadae162e173416a9507a9decc9f83d9ac6ebfaa Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Mon, 18 Oct 2021 10:30:55 +0100 Subject: [PATCH] Squashed 'external/devlib/' changes from 0e0417c6b..3f92d92a3 3f92d92a3 ssh: Reduce number of opened channels git-subtree-dir: external/devlib git-subtree-split: 3f92d92a3f7d44a46d69dd10a1fe4bbeca11836e --- devlib/utils/ssh.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/devlib/utils/ssh.py b/devlib/utils/ssh.py index 2586d6261..3a92fb553 100644 --- a/devlib/utils/ssh.py +++ b/devlib/utils/ssh.py @@ -410,8 +410,11 @@ class SshConnection(SshConnectionBase): def _get_progress_cb(self): return self.transfer_mgr.progress_cb if self.transfer_mgr is not None else None - @functools.lru_cache() - def _get_sftp(self, timeout): + # Limit the number of opened channels to a low number, since some servers + # will reject more connections request. For OpenSSH, this is controlled by + # the MaxSessions config. + @functools.lru_cache(maxsize=1) + def _cached_get_sftp(self): try: sftp = self.client.open_sftp() except paramiko.ssh_exception.SSHException as e: @@ -419,6 +422,10 @@ class SshConnection(SshConnectionBase): raise TargetStableError('The SSH server does not support SFTP. Please install and enable appropriate module.') from e else: raise + return sftp + + def _get_sftp(self, timeout): + sftp = self._cached_get_sftp() sftp.get_channel().settimeout(timeout) return sftp -- GitLab