PYTHON-6074 Fix pool deadlock when a greenlet is killed during checkin - #23
Closed
blink1073 wants to merge 10 commits into
Closed
PYTHON-6074 Fix pool deadlock when a greenlet is killed during checkin#23blink1073 wants to merge 10 commits into
blink1073 wants to merge 10 commits into
Conversation
# Conflicts: # doc/changelog.rst
Under gevent, notify() is a yield point, so a kill delivered inside it left accounted False and the fallback decremented the accounting a second time. Set the flag before notify() so only interruption during condition acquisition triggers the fallback.
Adds a test interrupting the error handler while it waits to acquire size_cond, covering the fallback that re-applies the checkout accounting.
When AMPLIFY_RACE is enabled the test reassigns gevent.thread.sleep globally; register a cleanup so the widened sleep window doesn't leak into later tests.
blink1073
commented
Sep 8, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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-6074
Changes in this PR
Under gevent, killing a greenlet that is checking a connection back into the pool can leave the pool's
requestsandactive_socketscounters permanently inflated atmaxPoolSize. Every later checkout then blocks forever on the size-gate wait, freezing all database operations for the process. This change makes the pool's checkin accounting uninterruptible by aGreenletExit, so the counters and the connection are always restored.Pool.checkinapply its counter decrement and connection return in one critical section, re-applying them if aGreenletExitinterrupts before they complete.test_gevent_kill_churn_deadlock, which runs workers and a killing reaper under gevent and fails if operations stall.Test Plan
waitQueueTimeoutMS); the same script runs clean for 5 minutes with the fix.test_gevent_task,test_gevent_timeout,test_gevent_timeout_when_creating_connection) still pass.just lintandjust typingare clean.