diff options
Diffstat (limited to 'paramiko/client.py')
-rw-r--r-- | paramiko/client.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/paramiko/client.py b/paramiko/client.py index 80c956cd..c3cbcb9d 100644 --- a/paramiko/client.py +++ b/paramiko/client.py @@ -350,6 +350,10 @@ class SSHClient(ClosingContextManager): # Break out of the loop on success break except socket.error as e: + # As mentioned in socket docs it is better + # to close sockets explicitly + if sock: + sock.close() # Raise anything that isn't a straight up connection error # (such as a resolution error) if e.errno not in (ECONNREFUSED, EHOSTUNREACH): |