Repository navigation
fix(transport): Keep the longest active rate limit - #8297
Open
sentry-junior[bot] wants to merge 1 commit into
Open
sentry-junior[bot] wants to merge 1 commit into
sentry-junior[bot] wants to merge 1 commit into
Conversation
A shorter rate limit replaced a longer one that was still active, both for repeated categories in one X-Sentry-Rate-Limits header and across responses, including the all-categories limit set by a 429. The SDK then sent that category before the longer quota expired. The deadlines are now stored in a private _RateLimits class. Its only write operation, update, keeps the later of the stored and the new deadline, so no update path can shorten an active limit. The backing dict is name-mangled and the class uses __slots__. Fixes #8296 Co-Authored-By: Daniel Szoke <7881302+szokeasaurusrex@users.noreply.github.com>
Contributor
Coverage Results 📊✅ 139245 passed | ⏭️ 7857 skipped | Total: 147102 | Pass Rate: 94.66% | Execution Time: 436m 10s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 85.71% (18 of 21 changed executable lines covered; target 80%). Changed files with executable lines (1)
Coverage diff@@ Coverage Diff @@
## master #8297 +/-##
==========================================
- Coverage 90.23% 90.22% -0.01%
==========================================
Files 203 203 —
Tracked lines 27335 27348 +13
Branches 10246 10250 +4
==========================================
+ Hits 24663 24672 +9
- Misses 2672 2676 +4
- Partials 1556 1558 +2Generated by Coverage Action |
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
HttpTransportCorestored the last rate limit it saw for each category, so a shorter limit replaced a longer one that was still active. This happened for repeated categories in oneX-Sentry-Rate-Limitsheader (3600:error:organization, 0:error:projectleft errors unlimited), across responses, and for the all-categories limit that a 429 sets. The spec requires keeping the longer limit.The deadlines now live in a private
_RateLimitsclass insentry_sdk/transport.py. Its only write operation,update(category, until), keeps the later of the stored and the new deadline. Its read methods areis_active(category)andany_active(). Both update paths in_update_rate_limits(theX-Sentry-Rate-Limitsheader, andRetry-Afteror the 60-second default on a 429) callupdate, and the sync and async transports share that code throughHttpTransportCore. Because the type enforces the rule, there is no separate fix per update path.What enforces the rule:
_RateLimitshas no setter, no__setitem__, and no other mapping methods. Its backing dict is name-mangled (__deadlines), and__slots__prevents adding attributes to an instance. Python cannot enforce full privacy: code can still reach the dict as_RateLimits__deadlines, or replacetransport._disabled_untilwith a new object._disabled_untilkeeps its name but is no longer a dict. It is a private attribute, so public API is unchanged.This follows the fix for the same bug in the Rust SDK: getsentry/sentry-rust#1409, reported by @itsrayeedscodespace, fixed in getsentry/sentry-rust#1410 with a
RateLimitTimeouttype whose only mutator keeps the later deadline.Issues
via @szokeasaurusrex.
--
View Session [Sentry]