Skip to content

fix: keep an active rate limit when a later header is shorter - #8336

Draft
Kayvan-Zahiri wants to merge 1 commit into
getsentry:masterfrom
Kayvan-Zahiri:keep-longer-rate-limit
Draft

Kayvan-Zahiri wants to merge 1 commit into
getsentry:masterfrom
Kayvan-Zahiri:keep-longer-rate-limit

Conversation

@Kayvan-Zahiri

Copy link
Copy Markdown

Fixes #8296.

HttpTransportCore stored rate limits with dict.update, so a later shorter limit replaced a longer one that was still active. The same header can do it on its own: 3600:error:organization, 0:error:project left errors unlimited. A later Retry-After on 429 did the same to the all-categories limit.

The transport spec says to keep the longer deadline. A new limit is stored only when it ends later than the one already recorded, so an expired deadline still gives way to a fresh one.

Tests:

  • unit: a shorter deadline does not replace a longer one, and a new deadline replaces an expired one
  • client: 3600:error then 0:error in one header keeps the long deadline, a later 1:error does not shorten it, and a 1 second Retry-After does not shorten an active global limit

tests/test_transport.py — test_shorter_rate_limit_keeps_the_longer_deadline, test_rate_limit_header_does_not_shorten_active_limit, and the existing parse tests. 7 passed.

No live Sentry project. I used AI assistance for the patch.

Made with Cursor

The transport spec says a new shorter limit must not replace one that is still running.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Kayvan-Zahiri Kayvan-Zahiri changed the title Keep an active rate limit when a later header is shorter fix: keep an active rate limit when a later header is shorter Nov 19, 2026

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rate limits from later headers shorten longer active limits

1 participant