Skip to content

PYTHON-5885 - Client Backpressure with retryAfterMS#2877

Open
NoahStapp wants to merge 16 commits into
mongodb:masterfrom
NoahStapp:backpressure-v2
Open

PYTHON-5885 - Client Backpressure with retryAfterMS#2877
NoahStapp wants to merge 16 commits into
mongodb:masterfrom
NoahStapp:backpressure-v2

Conversation

@NoahStapp

Copy link
Copy Markdown
Contributor

PYTHON-5885

Changes in this PR

Adds retryAfterMS support for backoff calculation on retryable overload errors.

Test Plan

Adds a new prose test test_05_overload_errors_with_retryafterms_override_backoff to verify the retryAfterMS behavior. Note that this new test requires a server with retryAfterMS support.

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?
@codecov-commenter

codecov-commenter commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@NoahStapp NoahStapp marked this pull request as ready for review July 1, 2026 15:50
@NoahStapp NoahStapp requested a review from a team as a code owner July 1, 2026 15:50
@NoahStapp NoahStapp requested review from aclark4life and Copilot July 1, 2026 15:50
@NoahStapp

Copy link
Copy Markdown
Contributor Author

Note: SERVER-130142 will rename retryAfterMS to baseBackoffMS. That change will require the spec to update as well as this PR.

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.

Pull request overview

Adds support for using retryAfterMS from retryable overload errors to influence the client’s adaptive retry backoff, plus updates handshake backpressure metadata and related tests/docs.

Changes:

  • Parse and propagate retryAfterMS from server error documents into the overload backoff calculation.
  • Update hello/handshake backpressure field value (and metadata tests) to "2".
  • Add a new prose-style timing test validating that retryAfterMS reduces overload backoff.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
pymongo/errors.py Parses retryAfterMS from error details into PyMongoError.
pymongo/synchronous/mongo_client.py Uses retryAfterMS override when computing overload retry backoff (sync).
pymongo/asynchronous/mongo_client.py Uses retryAfterMS override when computing overload retry backoff (async).
pymongo/synchronous/helpers.py Adjusts backoff helper to accept an override base backoff (sync).
pymongo/asynchronous/helpers.py Adjusts backoff helper to accept an override base backoff (async).
pymongo/synchronous/pool.py Updates handshake hello backpressure value (sync).
pymongo/asynchronous/pool.py Updates handshake hello backpressure value (async).
test/test_client_backpressure.py Adds a new test for retryAfterMS-driven backoff behavior (sync).
test/asynchronous/test_client_backpressure.py Adds a new test for retryAfterMS-driven backoff behavior (async).
test/test_client_metadata.py Updates handshake backpressure assertion (sync).
test/asynchronous/test_client_metadata.py Updates handshake backpressure assertion (async).
doc/changelog.rst Updates changelog entry for 4.18.0.
Comment thread pymongo/errors.py Outdated
Comment thread pymongo/errors.py Outdated
Comment thread pymongo/synchronous/mongo_client.py Outdated
Comment thread pymongo/asynchronous/mongo_client.py Outdated
Comment thread test/test_client_metadata.py
Comment thread test/test_client_backpressure.py
Comment thread test/asynchronous/test_client_backpressure.py
Comment thread doc/changelog.rst Outdated
Comment thread pymongo/synchronous/mongo_client.py
Comment thread pymongo/asynchronous/mongo_client.py

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.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Comment thread doc/changelog.rst
Comment thread test/test_client_backpressure.py
Comment thread test/asynchronous/test_client_backpressure.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants