Repository navigation
fix(core): Keep the longest active rate limit for each category - #26410
Merged
Merged
Conversation
`updateRateLimits` stored the last limit it saw for a category, so a shorter limit could replace a longer one that was still active. The spec requires keeping the longer one. The parsing of the response now lives in a module-private function that only reports each category and deadline through a callback. It has no access to the stored limits. The callback in `updateRateLimits` is the only code that writes a limit, and it keeps the later of the stored and the new deadline, so no update path can shorten an active limit. Fixes #26409 Co-Authored-By: Daniel Szoke <7881302+szokeasaurusrex@users.noreply.github.com>
Contributor
size-limit report 📦Compared: 28237c9 (PR test merge using develop at 93949c4) Against: 93949c4 (develop) · base run #66413 ✅ Baseline matches: this diff contains only this PR's changes.
|
The transport keeps the rate limits across responses. Typing them as readonly makes a direct write to a deadline fail to compile, so the transport can only replace them with the result of `updateRateLimits`, which never shortens a limit. This also removes the comment on the writer callback.
Contributor
Optional E2E testsSome optional checks were not successful. They do not block the merge. 2 not successful, 61 successful. See the run.
Successful checks
|
JPeer264
approved these changes
Nov 17, 2026
JPeer264
left a comment
Member
There was a problem hiding this comment.
Thanks for bringing that to our SDK as well
With the longest entry in the middle of the header, the test fails if the code keeps the first or the last entry for a category instead of the longest one.
51 tasks done
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.
What
A shorter rate limit no longer replaces a longer one that is still active. This applies to a category repeated in one
X-Sentry-Rate-Limitsheader, to limits from later responses, and to thealllimit fromRetry-Afteror a 429 without headers.Why
The spec requires keeping the longer limit. @itsrayeedscodespace reported the same bug in the Rust SDK in getsentry/sentry-rust#1409, and getsentry/sentry-rust#1410 fixed it by putting the rule in one type instead of calling
maxat each assignment.Here, the header parsing is in a module-private
forEachRateLimitfunction. It has no reference to the stored limits and reports each category and deadline through a callback. That callback inupdateRateLimitsis the only code that writes a limit, and it keeps the later deadline, so a new update path in the parser cannot shorten a limit. The transport stores the limits asReadonly<RateLimits>, so it can only replace them with the result ofupdateRateLimits.RateLimits(Record<string, number>) andupdateRateLimitsare exported from@sentry/core, andreplay-internalpasses a plain{}. A branded or readonly public type would break that API, soRateLimitsstays a mutable record. TypeScript does not stop code insideupdateRateLimits, or a caller outside the transport that holds aRateLimitsobject, from writing to it directly.Closes #26409
via @szokeasaurusrex.
--
View Session [Sentry]