diff --git a/common_lib/utils/auth.py b/common_lib/utils/auth.py index f0384e7..a9b2a48 100644 --- a/common_lib/utils/auth.py +++ b/common_lib/utils/auth.py @@ -8,6 +8,16 @@ from config import settings from .ssl_transport import ssl_transport from .validators import validate_username as core_validate_username, validate_password as core_validate_password + +limits = httpx.Limits(max_keepalive_connections=200, max_connections=1000) +timeout = httpx.Timeout(connect=5.0, read=10.0, write=5.0, pool=5.0) + +client = httpx.AsyncClient( + transport=ssl_transport, + limits=limits, + timeout=timeout +) + auth_scheme = HTTPBearer() @@ -28,16 +38,16 @@ async def _fetch_current_user( user_agent = request.headers.get("User-Agent", "(unknown)") try: - async with httpx.AsyncClient(transport=ssl_transport, timeout=5.0) as client: - response = await client.post( - f"{settings.TOKEN_SERVICE}/decode", - json={ - "token": token, - "ip": ip, - "user_agent": user_agent, - "require_permissions": require_permissions - }, - ) + # async with httpx.AsyncClient(transport=ssl_transport, timeout=5.0) as client: + response = await client.post( + f"{settings.TOKEN_SERVICE}/decode", + json={ + "token": token, + "ip": ip, + "user_agent": user_agent, + "require_permissions": require_permissions + }, + ) except httpx.RequestError as e: print("_fetch_current_user error", e) raise HTTPException(status_code=status.HTTP_503_SERVICE_UNAVAILABLE, detail="Token service unavailable")