-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 2.6
-
Component/s: None
-
None
-
Fully Compatible
A socket is leaked and forever counts against max_pool_size in the following scenario:
1. MongoClient has at least two sockets in the pool, sockets A and B.
2. The client successfully calls authenticate() on socket A, and adds a credential to its credentials-cache.
3. The client checks socket B out of the pool, sees that B lacks the new credential, and authenticates on B.
4. Socket B raises a network error during authentication.
Two incorrect behaviors now occur:
- MongoClient throws a socket.error instead of AutoReconnect
- The socket is leaked and the max_pool_size semaphore is never incremented
The coding errors are in MongoClient.__simple_command, where a socket.error should be translated into AutoReconnect, and in MongoClient.__socket, which returns the socket only after OperationFailure, but should do so after any exception.
MongoReplicaSetClient has neither bug.
MongoClient and its predecessor Connection have never returned the socket to the pool after a network error in this code path, nor translated socket.error into AutoReconnect. The behavior became a major bug in PyMongo 2.6 with the PYTHON-436 feature. Beginning then, the pool enforced max_pool_size and it became critical to close and return sockets after network errors.
- related to
-
PYTHON-903 Properly handle network errors in auth
- Closed