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:
parent
598c0c1d3c
commit
84c0935fb2
@ -367,6 +367,8 @@ class SshConnection(SshConnectionBase):
|
|||||||
else:
|
else:
|
||||||
logger.debug('Using SFTP for file transfer')
|
logger.debug('Using SFTP for file transfer')
|
||||||
|
|
||||||
|
self.client = None
|
||||||
|
try:
|
||||||
self.client = self._make_client()
|
self.client = self._make_client()
|
||||||
atexit.register(self.close)
|
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):
|
def _make_client(self):
|
||||||
if self.strict_host_check:
|
if self.strict_host_check:
|
||||||
policy = RejectPolicy
|
policy = RejectPolicy
|
||||||
|
Loading…
x
Reference in New Issue
Block a user