From 9fc992b423af02f383100cf3b043f8c85e620d17 Mon Sep 17 00:00:00 2001 From: "A. Jesse Jiryu Davis" Date: Thu, 23 Apr 2015 15:30:20 -0400 Subject: [PATCH] PYTHON-903 - Inc semaphore after network err with auth. There was a semaphore leak in MongoReplicaSet.__socket, though not critical. After getting disconnected during auth, it discards the server's whole pool. Then it wakes the monitor and creates a new pool, recovering from the leak. That's fine unless, at the moment we wake the monitor, we're unlucky and it's just started running using the previous pool (due to periodic monitoring or whatever). In that case it can't get a socket, and tells the main thread it thinks the primary's down *again*. Thus we threw two errors instead of one, but we still recover eventually. --- pymongo/mongo_replica_set_client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pymongo/mongo_replica_set_client.py b/pymongo/mongo_replica_set_client.py index bfe990565..18aaf5fd1 100644 --- a/pymongo/mongo_replica_set_client.py +++ b/pymongo/mongo_replica_set_client.py @@ -1306,7 +1306,9 @@ class MongoReplicaSetClient(common.BaseObject): try: self.__check_auth(sock_info) - except OperationFailure: + except: + # No matter whether an auth failure or network error, increment + # the pool's semaphore by returning the socket. member.maybe_return_socket(sock_info) raise return sock_info