Skip to content

Conversation

@blink1073
Copy link
Member

@blink1073 blink1073 commented Dec 3, 2025

PYTHON-5528
PYTHON-5651

Summary

Adds unified and prose tests from mongodb/specifications#1862 and replaces the use of the _retry_overload with the retry helper method calls to ensure that servers are properly deprioritized. They needed to be done together to verify that the unified tests still work.

Changes in this PR

  • Unified tests added
  • Handshake prose test implemented
  • Backpressure prose test implemented
  • Replace _retry_overload with the retry helper method calls to ensure that servers are properly deprioritized

Testing Plan

Added unified and prose tests, testing as part of PR.

Screenshots (optional)

N/A

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?

Focus Areas for Reviewer (optional)

…r overloaded errors

(cherry picked from commit 95948d3def875f1efb4d912ab8f507f518604ef5)
(cherry picked from commit ebf65519f12d160da6d2088c22f6c69fad5a37d0)
@blink1073 blink1073 changed the title PYTHON-5528 Add exponential backoff to operation retry loop for server overloaded errors PYTHON-5528 & PYTHON-5651 Add exponential backoff to operation retry loop for server overloaded errors Dec 4, 2025
@blink1073 blink1073 marked this pull request as ready for review February 2, 2026 19:14
@blink1073 blink1073 requested a review from a team as a code owner February 2, 2026 19:14
@blink1073 blink1073 requested review from Jibola, NoahStapp and sleepyStick and removed request for a team February 2, 2026 19:15
await change_stream._initialize_cursor()
return change_stream

async def _conn_for_writes(
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the motivation behind the change from this centralized method to a bunch of def inner closures?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because we needed to pass a function to the retry helper class, and the logic for backpressure is centralized there

# If we need to apply backpressure to the first command,
# we will need to revert back to starting state.
if self._session is not None and self._session.in_transaction:
self._session._transaction.has_completed_command = True
Copy link
Contributor

Choose a reason for hiding this comment

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

How does being in a transaction here imply that the transaction has completed a command?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because we've just recorded a successful read

Comment on lines 2804 to 2807
always_retryable = exc.has_error_label(
"RetryableError"
) and exc.has_error_label("SystemOverloadedError")
overloaded = exc.has_error_label("SystemOverloadedError")
Copy link
Contributor

Choose a reason for hiding this comment

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

minor thought but it might be a smidge easier to read if it was like:

overloaded = exc.has_error_label("SystemOverloadedError")
always_retryable = exc.has_error_label("RetryableError") and overloaded

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call, done!

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.

5 participants