PYTHON-5202 WaitQueueTimeoutError should not clear the pool (#2192) [v4.11] (#2196)

Co-authored-by: Shane Harvey <shnhrv@gmail.com>
This commit is contained in:
mongodb-drivers-pr-bot[bot] 2025-03-12 12:21:42 -07:00 committed by GitHub
parent 112e29b30f
commit dc73514cba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 28 additions and 4 deletions

View File

@ -40,6 +40,7 @@ from pymongo.errors import (
OperationFailure,
PyMongoError,
ServerSelectionTimeoutError,
WaitQueueTimeoutError,
WriteError,
)
from pymongo.hello import Hello
@ -877,6 +878,8 @@ class Topology:
# Clear the pool.
await server.reset(service_id)
elif isinstance(error, ConnectionFailure):
if isinstance(error, WaitQueueTimeoutError):
return
# "Client MUST replace the server's description with type Unknown
# ... MUST NOT request an immediate check of the server."
if not self._settings.load_balanced:

View File

@ -36,6 +36,7 @@ from pymongo.errors import (
OperationFailure,
PyMongoError,
ServerSelectionTimeoutError,
WaitQueueTimeoutError,
WriteError,
)
from pymongo.hello import Hello
@ -875,6 +876,8 @@ class Topology:
# Clear the pool.
server.reset(service_id)
elif isinstance(error, ConnectionFailure):
if isinstance(error, WaitQueueTimeoutError):
return
# "Client MUST replace the server's description with type Unknown
# ... MUST NOT request an immediate check of the server."
if not self._settings.load_balanced:

View File

@ -111,6 +111,7 @@ from pymongo.errors import (
NetworkTimeout,
OperationFailure,
ServerSelectionTimeoutError,
WaitQueueTimeoutError,
WriteConcernError,
)
from pymongo.monitoring import ServerHeartbeatListener, ServerHeartbeatStartedEvent
@ -1311,8 +1312,16 @@ class TestClient(AsyncIntegrationTest):
self.assertAlmostEqual(30, client.options.server_selection_timeout)
async def test_waitQueueTimeoutMS(self):
client = await self.async_rs_or_single_client(waitQueueTimeoutMS=2000)
self.assertEqual((await async_get_pool(client)).opts.wait_queue_timeout, 2)
listener = CMAPListener()
client = await self.async_rs_or_single_client(
waitQueueTimeoutMS=10, maxPoolSize=1, event_listeners=[listener]
)
pool = await async_get_pool(client)
self.assertEqual(pool.opts.wait_queue_timeout, 0.01)
async with pool.checkout():
with self.assertRaises(WaitQueueTimeoutError):
await client.test.command("ping")
self.assertFalse(listener.events_by_type(monitoring.PoolClearedEvent))
async def test_socketKeepAlive(self):
pool = await async_get_pool(self.client)

View File

@ -100,6 +100,7 @@ from pymongo.errors import (
NetworkTimeout,
OperationFailure,
ServerSelectionTimeoutError,
WaitQueueTimeoutError,
WriteConcernError,
)
from pymongo.monitoring import ServerHeartbeatListener, ServerHeartbeatStartedEvent
@ -1270,8 +1271,16 @@ class TestClient(IntegrationTest):
self.assertAlmostEqual(30, client.options.server_selection_timeout)
def test_waitQueueTimeoutMS(self):
client = self.rs_or_single_client(waitQueueTimeoutMS=2000)
self.assertEqual((get_pool(client)).opts.wait_queue_timeout, 2)
listener = CMAPListener()
client = self.rs_or_single_client(
waitQueueTimeoutMS=10, maxPoolSize=1, event_listeners=[listener]
)
pool = get_pool(client)
self.assertEqual(pool.opts.wait_queue_timeout, 0.01)
with pool.checkout():
with self.assertRaises(WaitQueueTimeoutError):
client.test.command("ping")
self.assertFalse(listener.events_by_type(monitoring.PoolClearedEvent))
def test_socketKeepAlive(self):
pool = get_pool(self.client)