summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--paramiko/client.py3
1 files changed, 3 insertions, 0 deletions
diff --git a/paramiko/client.py b/paramiko/client.py
index 80c956cd..ae70ac0b 100644
--- a/paramiko/client.py
+++ b/paramiko/client.py
@@ -350,6 +350,9 @@ 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):