Skip to content

fix: keep the longer rate limit when a later response sends a shorter one - #5947

Closed
sentry-junior[bot] wants to merge 1 commit into
mainfrom
fix/rate-limit-keep-longest
Closed

sentry-junior[bot] wants to merge 1 commit into
mainfrom
fix/rate-limit-keep-longest

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

HttpTransportBase.ExtractRateLimits wrote each X-Sentry-Rate-Limits reset straight into a dictionary, so a later response with a shorter limit replaced a longer one that was still active. The rate limiting spec requires keeping the longer one.

A type enforces the rule, not the call site. The resets live in a new internal RateLimitResets class whose backing ConcurrentDictionary is private. Its only write operation, Extend, uses AddOrUpdate to store the later of the current and the new reset time, so no current or future update path can shorten an active limit. With that, the OrderBy(rl => rl.RetryAfter) in ExtractRateLimits, which only protected limits within a single header, is removed. No public API changes.

RetryAfterHandler (429 without X-Sentry-Rate-Limits) is unchanged. It short-circuits every request while its limit is active, so a later response cannot shorten it. Open question: a request already in flight when that limit is set could still return a 429 with a shorter Retry-After and overwrite it, if the transport can have two sends in flight at once.

Same bug and fix pattern as getsentry/sentry-rust#1409 (reported by @itsrayeedscodespace) and getsentry/sentry-rust#1410.

Closes #5945

via @szokeasaurusrex.

--

View Session [Sentry]

… one

`HttpTransportBase` stored rate limit resets in a dictionary that each response overwrote, so a shorter limit from a later response replaced a longer active one. The develop spec requires keeping the longer one.

The resets now live in an internal `RateLimitResets` type with a private dictionary. Its only write operation, `Extend`, uses `AddOrUpdate` to keep the later of the stored and the new reset time, so no update path can shorten an active limit. The `OrderBy` on `RetryAfter`, which only covered limits within a single header, is no longer needed.

Closes #5945

Co-Authored-By: Daniel Szoke <7881302+szokeasaurusrex@users.noreply.github.com>
@ric-oliv

ric-oliv commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Duplicate of getsentry/sentry-dotnet#5946.

@github-actions

Copy link
Copy Markdown
Contributor

Mutation testing breaks the lines a PR changes on purpose, one mutation at a time, and checks that a test fails each time. A changed line no test runs fails the check, and a mutant that survives the tests only warns. Full report

Sentry: tests caught 8 of 10 mutants on the changed lines

Location Mutation Replaced with Status
src/Sentry/Internal/Http/RateLimitResets.cs:11 Equality mutation current >= resetAt Survived
src/Sentry/Internal/Http/RateLimitResets.cs:14 Equality mutation kvp.Value >= now Survived

sentry-junior Bot added a commit 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>
@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.45%. Comparing base (0230c48) to head (d49d85c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5947   +/-   ##
=======================================
  Coverage   77.44%   77.45%           
=======================================
  Files         546      547    +1     
  Lines       20053    20054    +1     
  Branches     3962     3963    +1     
=======================================
+ Hits        15531    15533    +2     
+ Misses       3658     3657    -1     
  Partials      864      864           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

jamescrosswell pushed a commit 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shorter rate limit from a later response replaces longer one

2 participants