Skip to content

Commit 76474ba

Browse files
committed
fix: Propagate RedisTimeoutError from rate limit functions
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
1 parent d7b0f25 commit 76474ba

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

snuba/state/rate_limit.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from typing import Any, Iterator, MutableMapping, Optional, Sequence, Type
1212
from typing import ChainMap as TypingChainMap
1313

14+
from redis.exceptions import TimeoutError as RedisTimeoutError
15+
1416
from snuba import environment, state
1517
from snuba.redis import RedisClientKey, get_redis_client
1618
from snuba.state import get_configs, set_config
@@ -275,6 +277,8 @@ def rate_limit_start_request(
275277
concurrent = sum(next(pipe_results) for _ in range(rate_limit_shard_factor))
276278
else:
277279
concurrent = 0
280+
except RedisTimeoutError:
281+
raise
278282
except Exception as ex:
279283
# if something goes wrong, we don't want to block the request,
280284
# set the values such that they pass under any limit
@@ -311,6 +315,8 @@ def rate_limit_finish_request(
311315
pipe.zincrby(query_bucket, -float(max_query_duration_s), query_id)
312316
pipe.expire(query_bucket, max_query_duration_s)
313317
pipe.execute()
318+
except RedisTimeoutError:
319+
raise
314320
except Exception as ex:
315321
logger.exception(ex)
316322

0 commit comments

Comments
 (0)