Skip to content

Commit

Permalink
Clean up after paramiko client objects as they do not close correctly…
Browse files Browse the repository at this point in the history
… by themselves. Updated changelog.
  • Loading branch information
pkittenis committed Oct 11, 2017
1 parent 13ba5ed commit 54f47b5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
1 change: 1 addition & 0 deletions Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Fixes

* Remote path for SFTP operations was created incorrectly on Windows - #88 - thanks @moscoquera
* Parallel client key error when openssh config with a host name override was used - #93
* Clean up after paramiko clients

1.1.1
++++++
Expand Down
6 changes: 6 additions & 0 deletions pssh/ssh_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ def __init__(self, host,
else:
self._connect(self.client, real_host, self.port, **paramiko_kwargs)

def __del__(self):
try:
self.client.close()
except Exception:
pass

def _connect_tunnel(self, host, **paramiko_kwargs):
"""Connects to SSH server via an intermediate SSH tunnel server.
client (me) -> tunnel (ssh server to proxy through) ->
Expand Down
19 changes: 11 additions & 8 deletions pssh/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ def load_private_key(_pkey):
:type pkey: file/str"""
if not hasattr(_pkey, 'read'):
_pkey = open(_pkey)
for keytype in [RSAKey, DSSKey, ECDSAKey]:
try:
pkey = keytype.from_private_key(_pkey)
except SSHException:
_pkey.seek(0)
continue
else:
return pkey
try:
for keytype in [RSAKey, DSSKey, ECDSAKey]:
try:
pkey = keytype.from_private_key(_pkey)
except SSHException:
_pkey.seek(0)
continue
else:
return pkey
finally:
_pkey.close()
logger.error("Failed to load private key using all available key types "
"- giving up..")

Expand Down

0 comments on commit 54f47b5

Please sign in to comment.