Skip to content

Commit 18de676

Browse files
authored
PYTHON-2297 Close connection to avoid resource warning when auth fails (#443)
1 parent 84fd04e commit 18de676

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

pymongo/pool.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,8 +1200,8 @@ def _get_socket(self, all_credentials):
12001200
self.active_sockets += 1
12011201

12021202
# We've now acquired the semaphore and must release it on error.
1203+
sock_info = None
12031204
try:
1204-
sock_info = None
12051205
while sock_info is None:
12061206
try:
12071207
with self.lock:
@@ -1214,6 +1214,9 @@ def _get_socket(self, all_credentials):
12141214
sock_info = None
12151215
sock_info.check_auth(all_credentials)
12161216
except Exception:
1217+
if sock_info:
1218+
# We checked out a socket but authentication failed.
1219+
sock_info.close_socket(ConnectionClosedReason.ERROR)
12171220
self._socket_semaphore.release()
12181221
with self.lock:
12191222
self.active_sockets -= 1

0 commit comments

Comments
 (0)