Skip to content

fix(transport): Keep the longest active rate limit - #8297

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

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

Conversation

@sentry-junior

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

Copy link
Copy Markdown
Contributor

A shorter rate limit replaced a longer one that was still active, so the SDK resumed sending before the quota expired. For example, after X-Sentry-Rate-Limits: 3600:error:organization, 0:error:project, errors were sent immediately instead of being held for an hour. Sentry rejects those events anyway, so the SDK spends requests on data that is dropped. The spec requires keeping the longer limit.

The deadlines now live in a private _RateLimits class whose only write method keeps the later deadline, so no update path (header, Retry-After, 429) can shorten an active limit.

This is the same bug as getsentry/sentry-rust#1409, reported by @itsrayeedscodespace, and the same fix as getsentry/sentry-rust#1410.

Closes #8296

via @szokeasaurusrex.

--

View Session [Sentry]

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>
@szokeasaurusrex
szokeasaurusrex marked this pull request as ready for review November 16, 2026 13:09
@szokeasaurusrex
szokeasaurusrex requested a review from a team as a code owner November 16, 2026 13:09
@github-actions

Copy link
Copy Markdown
Contributor

Coverage Results 📊

✅ 139245 passed | ⏭️ 7857 skipped | Total: 147102 | Pass Rate: 94.66% | Execution Time: 436m 10s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +17
Passed Tests 📈 +17
Failed Tests —
Skipped Tests —

All tests are passing successfully.

✅ Patch coverage is 85.71% (18 of 21 changed executable lines covered; target 80%).
Project statement coverage is 90.22% (down 0.01 percentage points from base (e540bd6) to head (bbb516b)).

Changed files with executable lines (1)
File Patch coverage Changed executable lines
sentry_sdk/transport.py 85.71% 18/21 covered; missed: 239, 240, 500
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        +2

Generated by Coverage Action

@alexander-alderman-webb

Copy link
Copy Markdown
Collaborator

Closing because we're not prioritizing merging this right now.

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit bbb516b.

Main concerns: reach, host performance.

This label is a hint for reviewers, not an approval.

@szokeasaurusrex

Copy link
Copy Markdown
Member

Closing because we're not prioritizing merging this right now.

Reopening this, as it is not good that the SDK does not respect rate limits, and imo we should prioritize getting a fix in. cc @alexander-alderman-webb @sentrivana

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rate limits from later headers shorten longer active limits

2 participants