Skip to content

Commit e48365c

Browse files
authored
PYTHON-5202 WaitQueueTimeoutError should not clear the pool (#2192)
1 parent 34ca759 commit e48365c

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
@@ -113,6 +113,7 @@
113113
NetworkTimeout,
114114
OperationFailure,
115115
ServerSelectionTimeoutError,
116+
WaitQueueTimeoutError,
116117
WriteConcernError,
117118
)
118119
from pymongo.monitoring import ServerHeartbeatListener, ServerHeartbeatStartedEvent
@@ -1313,8 +1314,16 @@ async def test_server_selection_timeout(self):
13131314
self.assertAlmostEqual(30, client.options.server_selection_timeout)
13141315

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

13191328
async def test_socketKeepAlive(self):
13201329
pool = await async_get_pool(self.client)

test/test_client.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
NetworkTimeout,
103103
OperationFailure,
104104
ServerSelectionTimeoutError,
105+
WaitQueueTimeoutError,
105106
WriteConcernError,
106107
)
107108
from pymongo.monitoring import ServerHeartbeatListener, ServerHeartbeatStartedEvent
@@ -1272,8 +1273,16 @@ def test_server_selection_timeout(self):
12721273
self.assertAlmostEqual(30, client.options.server_selection_timeout)
12731274

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

12781287
def test_socketKeepAlive(self):
12791288
pool = get_pool(self.client)

0 commit comments

Comments
 (0)