Repository navigation
fix(transport): retain the longest active rate limit - #1410
Merged
szokeasaurusrex merged 3 commits intoNov 16, 2026
Merged
szokeasaurusrex merged 3 commits into
szokeasaurusrex merged 3 commits into
Conversation
Merge incoming quota expirations with stored deadlines instead of replacing them, including category groups, Retry-After, and headerless 429 fallback delays. Cover all categories and shorter/longer updates without changing header parsing. Co-Authored-By: GPT-6 <gpt-6@noreply.example.com>
Calling `.max(...)` at each assignment fixes the bug, but every future update path would also have to remember it. The deadlines are now stored in a private `RateLimitTimeout` type, defined in its own submodule so `RateLimiter` cannot reach the inner `Option<SystemTime>`. Its only mutator, `update`, keeps the later of the stored and the new deadline, so no update path can shorten a limit. Because the type enforces this, the unit tests added for each update path are removed. The changelog entry now links the PR instead of the issue. Fixes getsentry#1409 Co-Authored-By: Daniel Szoke <7881302+szokeasaurusrex@users.noreply.github.com>
Member
|
Hey @itsrayeedscodespace! Thank you for the PR. I have taken it over from here; I decided to refactor the rate limiter and introduced a new type that encapsulates the updating logic. Hopefully, this ensures that the same bug cannot be reintroduced in the future by someone forgetting to write I also removed the tests as they are no longer needed with the type system ensuring the updating logic. |
Address review feedback: move `ratelimit.rs` into `ratelimit/mod.rs` next to its `timeout` submodule, and make the `RateLimitTimeout` methods `pub`, since the struct itself is already `pub(super)`. References getsentry#1409 Co-Authored-By: Daniel Szoke <7881302+szokeasaurusrex@users.noreply.github.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #1410 +/- ##
==========================================
+ Coverage 73.81% 74.48% +0.66%
==========================================
Files 64 84 +20
Lines 7538 10153 +2615
==========================================
+ Hits 5564 7562 +1998
- Misses 1974 2591 +617 |
This was referenced Nov 16, 2026
Merged
szokeasaurusrex
enabled auto-merge (squash)
November 16, 2026 13:17
3 tasks done
sentry-junior Bot
added a commit
to getsentry/sentry-dotnet
that referenced
this pull request
Nov 16, 2026
Follows the approach of #5947 and getsentry/sentry-rust#1410. Co-Authored-By: Ricardo Oliveira <ricardo.oliveira@sentry.io>
jamescrosswell
pushed a commit
to getsentry/sentry-dotnet
that referenced
this pull request
Nov 16, 2026
… one (#5946) * fix: keep the longer rate limit when a later response sends a shorter one Closes #5945 Co-Authored-By: Ricardo Oliveira <ricardo.oliveira@sentry.io> * test: cover a longer rate limit replacing a shorter one * ref: enforce the longer rate limit in a RateLimitResets type Follows the approach of #5947 and getsentry/sentry-rust#1410. Co-Authored-By: Ricardo Oliveira <ricardo.oliveira@sentry.io> * test: cover a rate limit at its exact reset time Co-Authored-By: Ricardo Oliveira <ricardo.oliveira@sentry.io> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Ricardo Oliveira <ricardo.oliveira@sentry.io>
JPeer264
pushed a commit
to getsentry/sentry-javascript
that referenced
this pull request
Nov 17, 2026
## 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-Limits` header, to limits from later responses, and to the `all` limit from `Retry-After` or a 429 without headers. ## Why The [spec](https://develop.sentry.dev/sdk/foundations/transport/rate-limiting/#stage-2-determine-rate-limits) 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 `max` at each assignment. Here, the header parsing is in a module-private `forEachRateLimit` function. It has no reference to the stored limits and reports each category and deadline through a callback. That callback in `updateRateLimits` is 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 as `Readonly<RateLimits>`, so it can only replace them with the result of `updateRateLimits`. `RateLimits` (`Record<string, number>`) and `updateRateLimits` are exported from `@sentry/core`, and `replay-internal` passes a plain `{}`. A branded or readonly public type would break that API, so `RateLimits` stays a mutable record. TypeScript does not stop code inside `updateRateLimits`, or a caller outside the transport that holds a `RateLimits` object, from writing to it directly. Closes #26409 <!-- junior-request-attribution:start --> via @szokeasaurusrex. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A9964492fd8caae68d7e3609da276b3f9 --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A9964492fd8caae68d7e3609da276b3f9) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A9964492fd8caae68d7e3609da276b3f9/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Daniel Szoke <7881302+szokeasaurusrex@users.noreply.github.com>
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
A later, shorter quota currently replaces a longer active rate limit. For example,
3600:error:organization, 0:error:projectclears the one-hour error limit and allows sending again immediately. The same happens across separate responses, and when a shorterRetry-Afteror a headerless 429 response replaces the global limit. The rate limiting spec requires SDKs to keep the longer limit.The deadlines are now stored in a private
RateLimitTimeouttype, defined in its own submodule (sentry/src/transports/ratelimit/timeout.rs) soRateLimitercannot reach the innerOption<SystemTime>. Its only mutator,update, keeps the later of the stored deadline and the new one, so no update path can shorten a limit. Header parsing, category handling, and response-header precedence are unchanged.The first commit, by @itsrayeedscodespace, fixed this by calling
.max(...)at each assignment. The second commit moves the max intoRateLimitTimeout, so future update paths do not need to remember it, and drops the per-path unit tests from the first commit because the type enforces the behavior.Issues
via @szokeasaurusrex.
--
View Session [Sentry]