The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
refactor(caching): walk exception causes iteratively for the breaker timeout check
mateoad78a8f8d0a4
diff --git a/litellm/caching/redis_cache.py b/litellm/caching/redis_cache.pyindex de4dcb5aa27..742c7144784 100644--- a/litellm/caching/redis_cache.py+++ b/litellm/caching/redis_cache.py@@ -15,7 +15,7 @@ import hashlibimport inspectimport jsonimport time-from collections.abc import Awaitable, Callable, Sequence+from collections.abc import Awaitable, Callable, Iterator, Sequencefrom contextvars import ContextVarfrom dataclasses import dataclassfrom datetime import timedelta@@ -334,11 +334,22 @@ def _redis_timeout_error_types() -> tuple[type, ...]:return (RedisTimeoutError, TimeoutError)+_MAX_EXCEPTION_CAUSE_DEPTH: Final = 20+++def _exception_cause_chain(exc: BaseException) -> Iterator[BaseException]:+ current = exc # rebind-ok: advances one link per iteration of the bounded walk+ for _ in range(_MAX_EXCEPTION_CAUSE_DEPTH):+ yield current+ if current.__cause__ is None:+ return+ current = current.__cause__++def _is_redis_timeout_failure(exc: BaseException) -> bool:- """Follows __cause__: a blocking pool wait raises ConnectionError from asyncio.TimeoutError."""- if isinstance(exc, _redis_timeout_error_types()):- return True- return exc.__cause__ is not None and _is_redis_timeout_failure(exc.__cause__)+ """Walks __cause__: a blocking pool wait raises ConnectionError from asyncio.TimeoutError."""+ timeout_types: Final = _redis_timeout_error_types()+ return any(isinstance(cause, timeout_types) for cause in _exception_cause_chain(exc))class _BreakerMetrics: