- standalone script to test aiohttp client with timeout and without timeout

- debug logs to view timeout values
This commit is contained in:
harish876 2026-04-10 00:41:40 +00:00
parent 5f49f29f4e
commit dfae508200
3 changed files with 58 additions and 0 deletions

View file

@ -553,6 +553,9 @@ class BaseAzureLLM(BaseOpenAILLM):
max_retries = litellm_params.get("max_retries")
timeout = litellm_params.get("timeout")
verbose_logger.debug(
"Azure initialize_azure_sdk_client litellm_params timeout=%s", timeout
)
if (
not api_key
and azure_ad_token_provider is None

View file

@ -292,6 +292,7 @@ class LiteLLMAiohttpTransport(AiohttpTransport):
) -> httpx.Response:
timeout = request.extensions.get("timeout", {})
sni_hostname = request.extensions.get("sni_hostname")
verbose_logger.debug("AiohttpTransport.handle_async_request timeout=%s", timeout)
# Use helper to ensure we have a valid session for the current event loop
client_session = self._get_valid_client_session()

View file

@ -0,0 +1,54 @@
import argparse
import asyncio
import time
import aiohttp
import httpx
from litellm.llms.custom_httpx.aiohttp_transport import LiteLLMAiohttpTransport
async def main() -> None:
parser = argparse.ArgumentParser(
description="Single httpbin delay test for LiteLLM aiohttp transport timeouts."
)
parser.add_argument("--delay-seconds", type=int, default=5)
parser.add_argument("--timeout-seconds", type=float, default=2.0)
parser.add_argument("--pass-timeout", type=bool, default=False)
args = parser.parse_args()
url = f"https://httpbin.org/delay/{args.delay_seconds}"
timeout = httpx.Timeout(args.timeout_seconds)
transport = LiteLLMAiohttpTransport(
client=lambda: aiohttp.ClientSession(trust_env=True)
)
print(f"url={url}")
print(f"timeout={args.timeout_seconds}s")
started_at = time.perf_counter()
try:
request = httpx.Request(
method="GET",
url=url,
extensions={"timeout": timeout.as_dict() if args.pass_timeout else {}},
)
print(timeout.as_dict() if args.pass_timeout else {})
print(f"request.extensions['timeout']={request.extensions.get('timeout')}")
response = await transport.handle_async_request(request)
elapsed = time.perf_counter() - started_at
print(f"SUCCESS status_code={response.status_code} elapsed_s={elapsed:.2f}")
print("If elapsed is much greater than timeout, timeout is not respected.")
except Exception as e:
elapsed = time.perf_counter() - started_at
print(
f"EXCEPTION type={type(e).__name__} elapsed_s={elapsed:.2f} detail={e}"
)
finally:
await transport.aclose()
if __name__ == "__main__":
asyncio.run(main())