Skip to content

Commit 05d42d2

Browse files
committed
PYTHON-5202 WaitQueueTimeoutError should not clear the pool
1 parent 7ef18af commit 05d42d2

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

pymongo/asynchronous/topology.py

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
OperationFailure,
4242
PyMongoError,
4343
ServerSelectionTimeoutError,
44+
WaitQueueTimeoutError,
4445
WriteError,
4546
)
4647
from pymongo.hello import Hello
@@ -892,6 +893,8 @@ async def _handle_error(self, address: _Address, err_ctx: _ErrorContext) -> None
892893
# Clear the pool.
893894
await server.reset(service_id)
894895
elif isinstance(error, ConnectionFailure):
896+
if isinstance(error, WaitQueueTimeoutError):
897+
return
895898
# "Client MUST replace the server's description with type Unknown
896899
# ... MUST NOT request an immediate check of the server."
897900
if not self._settings.load_balanced:

pymongo/synchronous/topology.py

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
OperationFailure,
3838
PyMongoError,
3939
ServerSelectionTimeoutError,
40+
WaitQueueTimeoutError,
4041
WriteError,
4142
)
4243
from pymongo.hello import Hello
@@ -890,6 +891,8 @@ def _handle_error(self, address: _Address, err_ctx: _ErrorContext) -> None:
890891
# Clear the pool.
891892
server.reset(service_id)
892893
elif isinstance(error, ConnectionFailure):
894+
if isinstance(error, WaitQueueTimeoutError):
895+
return
893896
# "Client MUST replace the server's description with type Unknown
894897
# ... MUST NOT request an immediate check of the server."
895898
if not self._settings.load_balanced:

test/asynchronous/test_client.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
NetworkTimeout,
112112
OperationFailure,
113113
ServerSelectionTimeoutError,
114+
WaitQueueTimeoutError,
114115
WriteConcernError,
115116
)
116117
from pymongo.monitoring import ServerHeartbeatListener, ServerHeartbeatStartedEvent
@@ -1311,8 +1312,16 @@ async def test_server_selection_timeout(self):
13111312
self.assertAlmostEqual(30, client.options.server_selection_timeout)
13121313

13131314
async def test_waitQueueTimeoutMS(self):
1314-
client = await self.async_rs_or_single_client(waitQueueTimeoutMS=2000)
1315-
self.assertEqual((await async_get_pool(client)).opts.wait_queue_timeout, 2)
1315+
listener = CMAPListener()
1316+
client = await self.async_rs_or_single_client(
1317+
waitQueueTimeoutMS=10, maxPoolSize=1, event_listeners=[listener]
1318+
)
1319+
pool = await async_get_pool(client)
1320+
self.assertEqual(pool.opts.wait_queue_timeout, 0.01)
1321+
async with pool.checkout():
1322+
with self.assertRaises(WaitQueueTimeoutError):
1323+
await client.test.command("ping")
1324+
self.assertFalse(listener.events_by_type(monitoring.PoolClearedEvent))
13161325

13171326
async def test_socketKeepAlive(self):
13181327
pool = await async_get_pool(self.client)

test/test_client.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
NetworkTimeout,
101101
OperationFailure,
102102
ServerSelectionTimeoutError,
103+
WaitQueueTimeoutError,
103104
WriteConcernError,
104105
)
105106
from pymongo.monitoring import ServerHeartbeatListener, ServerHeartbeatStartedEvent
@@ -1270,8 +1271,16 @@ def test_server_selection_timeout(self):
12701271
self.assertAlmostEqual(30, client.options.server_selection_timeout)
12711272

12721273
def test_waitQueueTimeoutMS(self):
1273-
client = self.rs_or_single_client(waitQueueTimeoutMS=2000)
1274-
self.assertEqual((get_pool(client)).opts.wait_queue_timeout, 2)
1274+
listener = CMAPListener()
1275+
client = self.rs_or_single_client(
1276+
waitQueueTimeoutMS=10, maxPoolSize=1, event_listeners=[listener]
1277+
)
1278+
pool = get_pool(client)
1279+
self.assertEqual(pool.opts.wait_queue_timeout, 0.01)
1280+
with pool.checkout():
1281+
with self.assertRaises(WaitQueueTimeoutError):
1282+
client.test.command("ping")
1283+
self.assertFalse(listener.events_by_type(monitoring.PoolClearedEvent))
12751284

12761285
def test_socketKeepAlive(self):
12771286
pool = get_pool(self.client)

0 commit comments

Comments
 (0)