mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-05 02:41:56 +00:00
fix(proxy): add auth reconnect lock timeout budget
This commit is contained in:
parent
2c02d1e55b
commit
c0a395ac89
1 changed files with 28 additions and 1 deletions
|
|
@ -2289,6 +2289,10 @@ class PrismaClient:
|
|||
self._db_auth_reconnect_timeout_seconds: float = max(
|
||||
0.5, float(os.getenv("PRISMA_AUTH_RECONNECT_TIMEOUT_SECONDS", "2.0"))
|
||||
)
|
||||
self._db_auth_reconnect_lock_timeout_seconds: float = max(
|
||||
0.0,
|
||||
float(os.getenv("PRISMA_AUTH_RECONNECT_LOCK_TIMEOUT_SECONDS", "0.1")),
|
||||
)
|
||||
verbose_proxy_logger.debug("Success - Created Prisma Client")
|
||||
|
||||
def get_request_status(
|
||||
|
|
@ -3587,6 +3591,7 @@ class PrismaClient:
|
|||
reason: str,
|
||||
force: bool = False,
|
||||
timeout_seconds: Optional[float] = None,
|
||||
lock_timeout_seconds: Optional[float] = None,
|
||||
) -> bool:
|
||||
"""
|
||||
Attempt to reconnect the Prisma client in a singleflight manner.
|
||||
|
|
@ -3606,7 +3611,7 @@ class PrismaClient:
|
|||
)
|
||||
return False
|
||||
|
||||
async with self._db_reconnect_lock:
|
||||
async def _attempt_reconnect_inside_lock() -> bool:
|
||||
now = time.time()
|
||||
if (
|
||||
force is False
|
||||
|
|
@ -3642,6 +3647,28 @@ class PrismaClient:
|
|||
|
||||
return reconnect_succeeded
|
||||
|
||||
if lock_timeout_seconds is None:
|
||||
async with self._db_reconnect_lock:
|
||||
return await _attempt_reconnect_inside_lock()
|
||||
|
||||
try:
|
||||
await asyncio.wait_for(
|
||||
self._db_reconnect_lock.acquire(),
|
||||
timeout=lock_timeout_seconds,
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
verbose_proxy_logger.debug(
|
||||
"Skipping DB reconnect attempt due to lock acquisition timeout. reason=%s timeout=%ss",
|
||||
reason,
|
||||
lock_timeout_seconds,
|
||||
)
|
||||
return False
|
||||
|
||||
try:
|
||||
return await _attempt_reconnect_inside_lock()
|
||||
finally:
|
||||
self._db_reconnect_lock.release()
|
||||
|
||||
async def start_db_health_watchdog_task(self) -> None:
|
||||
"""
|
||||
Start a background task that probes DB health and attempts reconnect on failure.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue