ref(ratelimiter): Reduce redis socket timeout and emit metric on timeout#7662
Merged
ref(ratelimiter): Reduce redis socket timeout and emit metric on timeout#7662
Conversation
Reduce the rate limiter Redis socket timeout from 0.5s to 0.1s to fail faster when Redis is slow or unavailable. Additionally, emit a metric (ratelimiter_redis_timeout) when a timeout occurs to enable monitoring. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
volokluev
reviewed
Jan 22, 2026
| pipe.expire(query_bucket, max_query_duration_s) | ||
| pipe.execute() | ||
| except Exception as ex: | ||
| logger.exception(ex) |
Member
There was a problem hiding this comment.
you don't want to log this exeption. it just becomes a sentry error and we want to avoid that.
Only emit metric for Redis timeout errors without logging, since timeouts are expected when Redis is slow and logging would be noisy. Other exceptions continue to be logged. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Member
|
Also, I don't think this is where we want to try/catch things. All of these errors happen in the allocation policy and this is not the only rate limiter that we use. (We also use a sliding window rate limiter for different policies). I think this change is better made in |
The metric is already emitted in the dedicated RedisTimeoutError handler, so no need to check for it again in the generic Exception handler. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Consolidate the error return path by using a finally block to check if an exception occurred and return the fail-open stats. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
a3c3671 to
c7f29b1
Compare
Move the RedisTimeoutError handling from rate_limit.py to allocation_policies/__init__.py. This covers all rate limiters (including sliding window) since they all go through the allocation policy base class. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
volokluev
approved these changes
Jan 23, 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.
Summary
ratelimiter_redis_timeoutwhen a Redis timeout occurs, tagged with the function (start_requestorfinish_request) where it happenedTest plan
ratelimiter_redis_timeoutmetric🤖 Generated with Claude Code