fix: Propagate expected exceptions from rate limit functions#7736
Merged
fix: Propagate expected exceptions from rate limit functions#7736
Conversation
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
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>
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>
54c399d to
b3959e2
Compare
…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>
onewland
approved these changes
Feb 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stop reporting errors on expected transient exceptions during allocation policy evaluation.
rate_limit_start_requestandrate_limit_finish_requesthave broadexcept Exceptionhandlers that calllogger.exception(), which reports errors even for expected conditions like Redis timeouts and unexpected pipeline result counts (StopIteration). However, the baseAllocationPolicyclass can handle these at a higher level — incrementing afail_openmetric and continuing without error logging.This change re-raises
RedisTimeoutErrorandStopIterationfrom the low-level rate limit functions so they propagate to the allocation policy base class, which handles them by failing open with a metric (reasontagged by exception type) and avoiding noisy error reports.