-
Notifications
You must be signed in to change notification settings - Fork 243
DRIVERS-3535 - Client Backpressure with retryAfterMS #1953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NoahStapp
wants to merge
16
commits into
mongodb:master
Choose a base branch
from
NoahStapp:DRIVERS-3535
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 12 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9b52910
DRIVERS-3535 - Client Backpressure with retryAfterMS
NoahStapp 5af946f
Clarity
NoahStapp 90e37d9
Update changelog
NoahStapp d57a0a4
Update source/client-backpressure/client-backpressure.md
NoahStapp 1dfcedb
SZ review
NoahStapp 07581aa
Update source/client-backpressure/tests/README.md
NoahStapp c662156
_MAX_BACKOFF applies to retryAfterMS
NoahStapp e4abae5
Simplify backoff formula
NoahStapp 63426b9
Update retryAfterMS prose test
NoahStapp 6d6a071
Cleanup test
NoahStapp 2ad0956
Update pseudocode
NoahStapp 132c52b
SS review
NoahStapp 540e477
SS review
NoahStapp 3618b6b
Conciseness cleanup
NoahStapp 81e9c1b
Formatting
NoahStapp 45e90e6
JY review
NoahStapp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,12 +129,16 @@ rules: | |
| - To retry `runCommand`, both [retryWrites](../retryable-writes/retryable-writes.md#retrywrites) and | ||
| [retryReads](../retryable-reads/retryable-reads.md#retryreads) MUST be enabled. See | ||
| [Why must both `retryWrites` and `retryReads` be enabled to retry runCommand?](client-backpressure.md#why-must-both-retrywrites-and-retryreads-be-enabled-to-retry-runcommand) | ||
| 3. If the request is eligible for retry (as outlined in step 2 above), the client MUST apply exponential backoff | ||
| according to the following formula: `backoff = jitter * min(MAX_BACKOFF, BASE_BACKOFF * 2^(attempt - 1))` | ||
| - `jitter` is a random jitter value between 0 and 1. | ||
| - `BASE_BACKOFF` is constant 100ms. | ||
| - `MAX_BACKOFF` is 10000ms. | ||
| - This results in delays of 100ms and 200ms before accounting for jitter. | ||
| 3. If the request is eligible for retry (as outlined in step 2 above), the client MUST apply backoff according to the | ||
| following rules: | ||
| 1. If `retryAfterMS` is present on the error and has a positive value, use the following formula: | ||
| `backoff = jitter * min(MAX_BACKOFF, retryAfterMS.value * 2^(attempt - 1))` | ||
| - `jitter` is a random jitter value between 0 and 1. | ||
| - `BASE_BACKOFF` is constant 100ms. | ||
| - `MAX_BACKOFF` is 10000ms. | ||
| - `retryAfterMS.value` is the value of the error's `retryAfterMS` field. | ||
| 2. Otherwise, use `BASE_BACKOFF` instead of `retryAfterMS.value` in the same formula. | ||
| - This results in delays of 100ms and 200ms before accounting for jitter. | ||
| 4. If the request is eligible for retry (as outlined in step 2 above) and `enableOverloadRetargeting` is enabled, the | ||
| client MUST add the previously used server's address to the list of deprioritized server addresses for | ||
| [server selection](../server-selection/server-selection.md). Drivers MUST expose `enableOverloadRetargeting` as a | ||
|
|
@@ -214,8 +218,14 @@ def execute_command_retryable(command, ...): | |
|
|
||
| if is_overload: | ||
| jitter = random.random() # Random float between [0.0, 1.0). | ||
| backoff = jitter * min(MAX_BACKOFF, BASE_BACKOFF * 2 ** (attempt - 1)) | ||
|
|
||
| # If present on the error, retryAfterMS sets the base backoff | ||
| retry_after_ms = exc.retry_after_ms | ||
| if retry_after_ms: | ||
| retry_after = retry_after / 1000 # Convert from milliseconds to seconds | ||
| backoff = jitter * min(MAX_BACKOFF, retry_after * 2 ** (attempt - 1)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, good catch. |
||
| # Otherwise fall back to BASE_BACKOFF | ||
| else: | ||
| backoff = jitter * min(MAX_BACKOFF, BASE_BACKOFF * 2 ** (attempt - 1)) | ||
| # If the delay exceeds the deadline, bail early. | ||
| if _csot.get_timeout(): | ||
| if time.monotonic() + backoff > _csot.get_deadline(): | ||
|
|
@@ -433,6 +443,8 @@ to understand and configure. | |
|
|
||
| ## Changelog | ||
|
|
||
| - 2026-06-16: Add support for retryAfterMS backoff calculation. | ||
|
|
||
| - 2026-04-14: Clarify correct retry behavior when a mix of overload and non-overload errors are encountered. | ||
|
|
||
| - 2026-03-30: Introduce phase 1 support without token buckets. | ||
|
|
||
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the retry_after should be set as BASE_BACKOFF, then set to the new value if retry_after_ms is given, then use a single line to set the backoff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙏 even more concise, thanks!