Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pymongo/asynchronous/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
OperationFailure,
PyMongoError,
ServerSelectionTimeoutError,
WaitQueueTimeoutError,
WriteError,
)
from pymongo.hello import Hello
Expand Down Expand Up @@ -877,6 +878,8 @@ async def _handle_error(self, address: _Address, err_ctx: _ErrorContext) -> None
# 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:
Expand Down
3 changes: 3 additions & 0 deletions pymongo/synchronous/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
OperationFailure,
PyMongoError,
ServerSelectionTimeoutError,
WaitQueueTimeoutError,
WriteError,
)
from pymongo.hello import Hello
Expand Down Expand Up @@ -875,6 +876,8 @@ def _handle_error(self, address: _Address, err_ctx: _ErrorContext) -> None:
# 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:
Expand Down
13 changes: 11 additions & 2 deletions test/asynchronous/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
NetworkTimeout,
OperationFailure,
ServerSelectionTimeoutError,
WaitQueueTimeoutError,
WriteConcernError,
)
from pymongo.monitoring import ServerHeartbeatListener, ServerHeartbeatStartedEvent
Expand Down Expand Up @@ -1311,8 +1312,16 @@ async def test_server_selection_timeout(self):
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)
Expand Down
13 changes: 11 additions & 2 deletions test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
NetworkTimeout,
OperationFailure,
ServerSelectionTimeoutError,
WaitQueueTimeoutError,
WriteConcernError,
)
from pymongo.monitoring import ServerHeartbeatListener, ServerHeartbeatStartedEvent
Expand Down Expand Up @@ -1270,8 +1271,16 @@ def test_server_selection_timeout(self):
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)
Expand Down
Loading