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.
Every failed checkout now restores its counters through one
accounted-guarded replay, replacing the per-mutation flags. Behavior,
lock regions, and telemetry ordering are unchanged.
…ling
Track notification completion separately from counter restoration so a
kill landing inside notify() retries the wake-up instead of stranding
waiters. Reword comments containing 'waiter', which the synchro
replacement table mangles ('aiter' is a substring).
A kill landing inside the connect cleanup's notify() (a gevent yield
point) could strand a checkout waiting at the maxConnecting gate. Retry
the notify with the accounted idiom so the wake-up survives.
The stress test now verifies that requests, _pending, and active_sockets drain, but it never checks operation_count, which is the counter this PR also makes transactional. A checkout can therefore leak the load metric while this regression test still passes; add an operation_count == 0 assertion to the post-settle checks.
Assert operation_count drains in stress test
test/test_client.py:2824
The stress test now verifies that requests, _pending, and active_sockets drain, but it never checks operation_count, which is the counter this PR also makes transactional. A checkout can therefore leak the load metric while this regression test still passes; add an operation_count == 0 assertion to the post-settle checks.
The reason will be displayed to describe this comment to others. Learn more.
Looks like this locks whether it needs to or not, how about something like this instead:
finally:
# Both conditions below read only local variables, so the lock
# is not needed to evaluate them; skip the acquire when there
# is no leftover work.
if not accounted or applied & ~notified:
async with self.size_cond:
if not accounted:
self._restore_applied(applied)
missing = applied & ~notified
if missing & _UNDO_REQUESTS:
self.size_cond.notify()
if missing & _UNDO_PENDING:
self._max_connecting_cond.notify()
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