1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-31 02:00:45 +00:00

utils/ssh: Try to free up resources during client creation

SshConnection._make_client() may throw exceptions for several reasons
(e.g., target is not ready yet). The client should be closed if that is
the case. Otherwise Python unittest like tools report resource warning
for 'unclosed socket', etc.

Signed-off-by: Douglas Raillard <douglas.raillard@arm.com>
Signed-off-by: Metin Kaya <metin.kaya@arm.com>
This commit is contained in:
Metin Kaya 2024-01-31 12:01:52 +00:00 committed by Marc Bonnici
parent 598c0c1d3c
commit 84c0935fb2

View File

@ -367,6 +367,8 @@ class SshConnection(SshConnectionBase):
else:
logger.debug('Using SFTP for file transfer')
self.client = None
try:
self.client = self._make_client()
atexit.register(self.close)
@ -387,6 +389,11 @@ class SshConnection(SshConnectionBase):
)
)
except BaseException:
if self.client is not None:
self.client.close()
raise
def _make_client(self):
if self.strict_host_check:
policy = RejectPolicy