You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An interrupted checkout could permanently stick the pool; the pool's accounting is now fully restored on failure.
Test Plan
Covered by the gevent killall race test and new deterministic regression tests. Repro: AMPLIFY_RACE=1 python -m pytest test/test_client.py::TestExhaustCursor::test_gevent_kill_churn_deadlock
Checklist
Checklist for Author
Did you update the changelog (if necessary)? (Not necessary — internal accounting fix.)
Is there test coverage?
Is any followup work tracked in a JIRA ticket? If so, add link(s). (None needed.)
Checklist for Reviewer
Does the title of the PR reference a JIRA Ticket?
Do you fully understand the implementation? (Would you be comfortable explaining how this code works to someone else?)
Is all relevant documentation (README or docstring) updated?
A BaseException (KeyboardInterrupt, CancelledError, GreenletExit)
landing inside Pool.checkout could leak checkout accounting: the size
gate (self.requests) was only rolled back after a socket was acquired,
and the maxConnecting _pending counter was only rolled back on the
happy path. Roll back both counters, with notify(), when a
BaseException interrupts the gate or the connection attempt. Rework
the gevent killall race test to amplify the checkout unwind windows
and assert the counters fully drain after the pool settles.
Initialize pool before try/finally to preserve watchdog failures
test/asynchronous/test_client.py:2853
pool is initialized only after the watchdog and liveness probe succeed. If either path raises (for example, the intended deadlock timeout), control still runs the finally block and then reaches the assertions at 2872-2874, where pool is unbound and the test reports UnboundLocalError instead of the actual failure. Initialize the pool before entering the try/finally and remove this late assignment.
Test plan references missing regression test
test/asynchronous/test_client.py:2749
The test plan names test/asynchronous/test_client.py::TestExhaustCursor::test_exhaust_cursor_enabled_killall, but this change only modifies test_gevent_kill_churn_deadlock, and no test with the documented name exists in the checkout. That command therefore collects no regression test; please update the plan or add/rename the intended test.
The reason will be displayed to describe this comment to others. Learn more.
Copilot review overview
🔵 Needs a closer look
Unresolved moderate issues remain in checkout counter rollback and asynchronous connection cleanup.
Review effort: Lite Findings: None
Previously missed (1)
In code that hasn't changed since last review
Rollback operation_count on every failed checkout
pymongo/asynchronous/pool.py:987
operation_count is incremented before this rollback block and is only decremented by _checkin_apply, which is reached only after a connection has been returned. A cancellation or other BaseException before that point therefore leaves operation_count permanently elevated (including failures while waiting on size_cond); subsequent checkouts keep the server-selection load metric inflated. Roll back this counter exactly once on every failed checkout and assert it in the new regression tests as well.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PYTHON-6136
Changes in this PR
An interrupted checkout could permanently stick the pool; the pool's accounting is now fully restored on failure.
Test Plan
Covered by the gevent killall race test and new deterministic regression tests. Repro:
AMPLIFY_RACE=1 python -m pytest test/test_client.py::TestExhaustCursor::test_gevent_kill_churn_deadlockChecklist
Checklist for Author
Checklist for Reviewer