Skip to content

Comments

fix: Propagate expected exceptions from rate limit functions#7736

Merged
phacops merged 4 commits intomasterfrom
fix/redis-timeout-rate-limit-propagation
Feb 18, 2026
Merged

fix: Propagate expected exceptions from rate limit functions#7736
phacops merged 4 commits intomasterfrom
fix/redis-timeout-rate-limit-propagation

Conversation

@phacops
Copy link
Contributor

@phacops phacops commented Feb 16, 2026

Stop reporting errors on expected transient exceptions during allocation policy evaluation.

rate_limit_start_request and rate_limit_finish_request have broad except Exception handlers that call logger.exception(), which reports errors even for expected conditions like Redis timeouts and unexpected pipeline result counts (StopIteration). However, the base AllocationPolicy class can handle these at a higher level — incrementing a fail_open metric and continuing without error logging.

This change re-raises RedisTimeoutError and StopIteration from the low-level rate limit functions so they propagate to the allocation policy base class, which handles them by failing open with a metric (reason tagged by exception type) and avoiding noisy error reports.

Let RedisTimeoutError propagate from rate_limit_start_request and
rate_limit_finish_request instead of catching it in the broad
except Exception handler and logging it as an error. The base
AllocationPolicy class already handles this exception by incrementing
a fail_open metric and continuing without error reporting.

Co-Authored-By: Claude <noreply@anthropic.com>

Agent transcript: https://claudescope.sentry.dev/share/wHR4-EZOiDwQJ-IiEz2-Vn3usNpLCr_rKh1D1NH3CY8
@phacops phacops requested a review from a team as a code owner February 16, 2026 20:44
Apply the same fail-open pattern to StopIteration (from unexpected
Redis pipeline result counts) as RedisTimeoutError: re-raise from
the low-level rate limit functions and handle at the AllocationPolicy
level with a metric instead of logging it as a bug.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@phacops phacops changed the title fix: Propagate RedisTimeoutError from rate limit functions fix: Propagate expected exceptions from rate limit functions Feb 18, 2026
StopIteration cannot be re-raised through the rate_limit() generator
due to PEP 479 (converted to RuntimeError). Handle it locally by
failing open without logging, while keeping the allocation policy
handlers for StopIteration from other code paths.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@phacops phacops force-pushed the fix/redis-timeout-rate-limit-propagation branch from 54c399d to b3959e2 Compare February 18, 2026 15:41
…quest

rate_limit_finish_request has no next() calls or generator expressions
that could raise StopIteration, unlike rate_limit_start_request.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@phacops phacops merged commit 8739f22 into master Feb 18, 2026
34 checks passed
@phacops phacops deleted the fix/redis-timeout-rate-limit-propagation branch February 18, 2026 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants