Repository navigation
fix(ratelimiter): split each rate limit at the comma before reading its fields - #2245
Merged
jpnurmi merged 2 commits intoOct 26, 2026
Merged
Conversation
…ts fields The scope field of an X-Sentry-Rate-Limits entry is optional, but the parser looked for the end of the categories with the next ':' anywhere in the rest of the header. A limit that left the scope out therefore ran past its own comma and swallowed the limit after it, so its categories matched nothing and were never rate limited. For "60:error, 120:session, 30:transaction" only the transaction limit applied; error and session were dropped and the SDK kept sending both. Splitting at the comma first, the way the other SDKs do, keeps each limit to its own fields.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2245 +/- ##
==========================================
- Coverage 75.63% 75.52% -0.12%
==========================================
Files 103 103
Lines 28263 28263
Branches 5180 5180
==========================================
- Hits 21378 21345 -33
- Misses 5540 5577 +37
+ Partials 1345 1341 -4 🚀 New features to boost your workflow:
|
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.
Summary
The scope field of an
X-Sentry-Rate-Limitsentry is optional, but the parser looked for the end of the categories with the next:anywhere in the remainder of the header. A limit that left the scope out therefore ran past its own comma and swallowed the limit after it.On
masteronly the transaction limit applies. For the first entry the parser takes everything up to the:beforesessionas the category list, so it readserror, 120, which matches no category and is silently discarded. The same happens tosession. The SDK carries on sending errors and sessions that the server has just asked it to stop sending.Headers where every limit carries a scope —
120:error:project:reason, 60:session:foo— are unaffected, which is why the existing tests pass: all of them supply a scope.Fix
Split each limit at the comma first, then read its fields, which is the order the other SDKs use.
sentry-python:The category and
;handling is unchanged.Tests
Two cases in
tests/unit/test_ratelimiter.c, both failing onmasterand passing here:rate_limit_header_without_scope—60:error, 120:session, 30:transaction, asserting all three apply.rate_limit_header_mixed_scopes—60:replay, 120:feedback:organization, 30:error;session, so a scoped and an unscoped limit sit next to each other, and asserting that nothing becomes a blanket limit.make test-unitis 616 passed (614 before, plus these two). Onmasterthe pair fails exactly as described.clang-format20.1.5 clean on both files.Note
I kept the existing behaviour of returning
falseon a malformed entry rather than skipping it and carrying on, since that is a separate decision.sentry-pythonskips the bad entry and keeps parsing the rest — happy to match that instead if you prefer.