Skip to content

PYTHON-6200 Reset monitor pools to prevent races with close() - #3161

Merged
NoahStapp merged 3 commits into
mongodb:mainfrom
NoahStapp:PYTHON-6200
Oct 30, 2026
Merged

NoahStapp merged 3 commits into
mongodb:mainfrom
NoahStapp:PYTHON-6200

Conversation

@NoahStapp

@NoahStapp NoahStapp commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

PYTHON-6200 follow-up

Changes in this PR

Reset monitor pools to prevent a race between the executor being stopped and the monitor being closed.

Test Plan

Existing test suite.

Checklist

Checklist for Author

  • Did you update the changelog (if necessary)?
  • Is there test coverage?
  • Is any followup work tracked in a JIRA ticket? If so, add link(s).

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?

Copilot AI balanced review requested due to automatic review settings October 29, 2026 14:47
@NoahStapp
NoahStapp requested a review from a team as a code owner October 29, 2026 14:47
@NoahStapp
NoahStapp requested a review from aclark4life October 29, 2026 14:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A deterministic regression test is still needed for the shutdown race in both Monitor and _RttMonitor, since the existing test can pass without exercising the problematic interleaving.

1 open issue
What changed in this PR

This PR addresses PYTHON-6200 by adding monitor-pool cleanup when an executor stops, preventing connections from surviving a shutdown race.

Changes:

  • Reset the main monitor’s connections during final cleanup.
  • Reset the round-trip-time monitor’s pool when its executor stops.
  • Mirror the asynchronous changes in the generated synchronous implementation.
File Description
pymongo/​synchronous/​monitor.py Mirrors the shutdown cleanup in synchronous monitors.
pymongo/​asynchronous/​monitor.py Adds final pool resets to both asynchronous monitor types.

Review effort: Balanced

Comment thread pymongo/asynchronous/monitor.py Resolved
@NoahStapp
NoahStapp merged commit 2c47940 into mongodb:main Oct 30, 2026
83 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants