Repository navigation
fix(transport): Keep the longest active rate limit - #3212
sentry-junior[bot] wants to merge 1 commit into
Conversation
A shorter rate limit could replace a longer one that was still active. When an x-sentry-rate-limits header listed the same category more than once, the last group won, so "3600:error:organization, 0:error:project" left errors unlimited. The deadlines now live in Sentry::Transport::RateLimits. Its only write operation, update, keeps the later of the stored and the new deadline, and every update path (each group of the rate limit header, Retry-After, and a 429 without headers) writes through it, so no path can shorten a limit. Transport#rate_limits still returns a Hash, now a copy of the deadlines. Fixes #3211 Co-Authored-By: Daniel Szoke <7881302+szokeasaurusrex@users.noreply.github.com>
|
Junior: does this change break public API? If not, it's good to mark ready for review |
|
No break to the documented API. The observable change is in mutation. The reader now returns a copy, so The second change is internal. The |
Fixes #3211
Origin: getsentry/sentry-rust#1409, the same bug in the Rust SDK, found by @itsrayeedscodespace. Pattern: getsentry/sentry-rust#1410, which enforces the rule with a type.
A shorter rate limit could replace a longer one that was still active.
parse_rate_limit_headerlet the last group per category win, so3600:error:organization, 0:error:projectleft errors unlimited. The rate limiting spec requires keeping the longer limit.What enforces the rule. The deadlines now live in
Sentry::Transport::RateLimits(@api private). Its only write method,update(category, deadline), keeps the later of the stored and the new deadline. It has no[]=,merge!,delete, or reader that returns its internal Hash;to_hreturns a copy. The HTTP transport writes every limit throughupdate: each group ofx-sentry-rate-limits(so repeated categories within one header are covered),Retry-After, a 429 without headers, and thenilall-categories limit.is_rate_limited?andany_rate_limited?delegate to the class.What Ruby cannot enforce. Code can still reach the internal Hash with
instance_variable_get, replaceTransport's@rate_limitsivar, or reopen the class. A subclass ofSentry::Transportthat wrote to@rate_limitsas a Hash would break; no transport in this repo does.Public API.
Transport#rate_limitswas anattr_readerthat returned the live Hash. It still returns aHashwith the same keys and values, but as a copy: reads ([],==,each) behave as before, and mutating it no longer changes the transport's limits. Only specs in this repo mutated it, to seed limits; they now useRateLimits#update. No other gem in the monorepo uses it. The copy is not frozen, because a frozen copy would make such writes raiseFrozenErrorin host apps instead of being ignored.via @szokeasaurusrex.
--
View Session [Sentry]