From 16a19f16c2f941e2f36bf8fdfb1233a123e8abf6 Mon Sep 17 00:00:00 2001 From: jibanez-staticduo Date: Fri, 18 Sep 2026 20:42:12 +0200 Subject: [PATCH] fix(realtime): remove empty exception handlers --- litellm/proxy/realtime_endpoints/call_sessions.py | 8 +++++--- litellm/proxy/realtime_endpoints/live.py | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/litellm/proxy/realtime_endpoints/call_sessions.py b/litellm/proxy/realtime_endpoints/call_sessions.py index 0827d4b5057..f2fb8e365e9 100644 --- a/litellm/proxy/realtime_endpoints/call_sessions.py +++ b/litellm/proxy/realtime_endpoints/call_sessions.py @@ -230,12 +230,14 @@ MAX_REALTIME_OFFER_BYTES: Final = 8 * 1024 * 1024 async def _cache_bounded_offer_body(request: Request) -> None: + content_length: int | None try: - if int(request.headers.get("content-length", "")) > MAX_REALTIME_OFFER_BYTES: - raise HTTPException(413, "Realtime offer exceeds the 8 MiB limit") + content_length = int(request.headers.get("content-length", "")) except ValueError: # A missing or non-numeric content length is checked while streaming below. - pass + content_length = None + if content_length is not None and content_length > MAX_REALTIME_OFFER_BYTES: + raise HTTPException(413, "Realtime offer exceeds the 8 MiB limit") if hasattr(request, "_body"): if len(request._body) > MAX_REALTIME_OFFER_BYTES: # pyright: ignore[reportPrivateUsage] # validate Starlette's cached body without consuming it again raise HTTPException(413, "Realtime offer exceeds the 8 MiB limit") diff --git a/litellm/proxy/realtime_endpoints/live.py b/litellm/proxy/realtime_endpoints/live.py index 663b31cc5fb..7d75c2100fa 100644 --- a/litellm/proxy/realtime_endpoints/live.py +++ b/litellm/proxy/realtime_endpoints/live.py @@ -1522,13 +1522,13 @@ async def websocket_live_session(websocket: WebSocket, session_id: str | None = await websocket.close(code=1008, reason="Live session rejected") except RuntimeError: # The peer may have closed the socket before the rejection response. - pass + return except Exception: try: await websocket.close(code=1011, reason="Live upstream connection failed") except RuntimeError: # The peer may have closed the socket before the failure response. - pass + return finally: if state.connection is not None: await state.connection.close()