Skip to content

Conversation

@NoahStapp
Copy link
Contributor

PYTHON-5642

Summary

Currently, cursor getMores against non-standalone, non-loadbalanced servers do not block for server selection, even if the pinned server for the operation is in an unknown state. This can cause the getMore to fail with a Connection pool paused error.

Changes in this PR

getMore operations now wait for server selection if their pinned server is in an unknown state.

Testing Plan

Added a new test test_server_selection_getMore_blocks.

Screenshots (optional)

Checklist

Checklist for Author

  • Did you update the changelog (if necessary)?
  • Is the intention of the code captured in relevant tests?
  • If there are new TODOs, has a related JIRA ticket been created?

Checklist for Reviewer {@primary_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?)
  • Have you checked for spelling & grammar errors?
  • Is all relevant documentation (README or docstring) updated?

@NoahStapp NoahStapp requested a review from a team as a code owner November 24, 2025 15:13
@NoahStapp NoahStapp requested a review from blink1073 November 24, 2025 15:13
@blink1073
Copy link
Member

Typing error:

Found 2 errors in 1 file (checked 148 source files)
"ServerDescription | None"; expected "ServerDescription"  [list-item]
                return [description] if description.is_server_type_known e...
                        ^~~~~~~~~~~
pymongo/topology_description.py:325: error: Item "None" of
"ServerDescription | None" has no attribute "is_server_type_known"  [union-attr]
                return [description] if description.is_server_type_known e...
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: Recipe `typing-mypy` failed on line 41 with exit code 1
error: Recipe `typing` failed on line 36 with exit code 1

# Ignore selectors when explicit address is requested.
description = self.server_descriptions().get(address)
return [description] if description else []
return [description] if description.is_server_type_known else []
Copy link
Member

Choose a reason for hiding this comment

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

Can description be None?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, in theory yes.

blink1073
blink1073 previously approved these changes Nov 24, 2025
Copy link
Member

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

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

LGTM!

- Removed support for Eventlet.
Eventlet is actively being sunset by its maintainers and has compatibility issues with PyMongo's dnspython dependency.
- Use Zstandard support from the standard library for Python 3.14+, and use ``backports.zstd`` for older versions.
- Fixed a bug that could cause ``AutoReconnect("connection pool paused")`` errors when cursors fetched more documents from the database after SDAM heartbeat failures.
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be a 4.15.5 release

@NoahStapp NoahStapp requested a review from blink1073 November 24, 2025 15:47
@blink1073
Copy link
Member

drivers-pr-bot please backport to v4.15

Copy link
Member

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

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

LGTM!

@NoahStapp NoahStapp merged commit 42cf340 into mongodb:master Nov 24, 2025
72 of 75 checks passed
@mongodb-dbx-release-bot
Copy link
Contributor

Sorry, unable to cherry-pick to v4.15, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
git checkout -b cherry-pick-v4.15-42cf3407c8878aad280b7ebf56f5b81665a12252 v4.15

git fetch origin 42cf3407c8878aad280b7ebf56f5b81665a12252
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
git cherry-pick -x -m1 42cf3407c8878aad280b7ebf56f5b81665a12252
  1. You will likely have some merge/cherry-pick conflicts here, fix them and commit:
git commit -am {message}
  1. Push to a named branch:
git push origin cherry-pick-v4.15-42cf3407c8878aad280b7ebf56f5b81665a12252
  1. Create a PR against branch v4.15. I would have named this PR:

"PYTHON-5642 - getMore operations should do server selection if the server is unknown (#2621) [v4.15]"

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.

2 participants