This commit is contained in:
Timothy Jaeryang Baek
2026-07-27 00:10:36 -04:00
parent 8ddf119570
commit 4a7d4ebada
4 changed files with 28 additions and 6 deletions
+9 -1
View File
@@ -28,6 +28,7 @@ from typing import Optional
import aiohttp
from open_webui.env import (
AIOHTTP_CLIENT_STREAM_IDLE_TIMEOUT,
AIOHTTP_CLIENT_TIMEOUT,
AIOHTTP_POOL_CONNECTIONS,
AIOHTTP_POOL_CONNECTIONS_PER_HOST,
@@ -39,6 +40,13 @@ log = logging.getLogger(__name__)
_session: Optional[aiohttp.ClientSession] = None
def get_client_timeout(stream: bool = False) -> aiohttp.ClientTimeout:
return aiohttp.ClientTimeout(
total=AIOHTTP_CLIENT_TIMEOUT,
sock_read=AIOHTTP_CLIENT_STREAM_IDLE_TIMEOUT if stream else None,
)
async def get_session() -> aiohttp.ClientSession:
"""Return the shared aiohttp ClientSession, creating it lazily."""
global _session
@@ -56,7 +64,7 @@ async def get_session() -> aiohttp.ClientSession:
else:
connector_kwargs['limit_per_host'] = 0 # aiohttp: 0 = unlimited
connector = aiohttp.TCPConnector(**connector_kwargs)
timeout = aiohttp.ClientTimeout(total=AIOHTTP_CLIENT_TIMEOUT)
timeout = get_client_timeout()
_session = aiohttp.ClientSession(
connector=connector,
timeout=timeout,