litellm/tests/test_litellm/llms/custom_httpx
Yassin Kortam 9d58923065
fix(langfuse): stop a collected httpx handler from closing a shared client (#35981)
A cached HTTPHandler hands its raw httpx.Client out to consumers that keep it
for the process lifetime. When the shared client cache expires the entry on its
TTL or evicts it under the 200-entry cap, nothing references the handler, so it
is collected and its finalizer closed the client those consumers still hold.
Langfuse ingestion then failed silently on the SDK's background flush thread
until the process restarted.

A finalizer running proves only that nothing references the handler; it proves
nothing about the client. Both handlers now close the client during finalization
only when they built it and are still its sole referrer, so an unshared client is
still released promptly and a handed-out one is left alone. That keeps the
pooled-socket reclamation the finalizer was providing, which measures identical
to base over 2000 handler create-and-drop cycles.

Explicit close() stays, now gated on _owns_client so the wrapper never closes a
caller-injected client, and __aexit__ routes through it.

LangFuseLogger also keeps a reference to the handler whose client it hands the
SDK. Previously that handler was a local that went out of scope immediately,
leaving the client reachable only from the SDK. It still shares the cached
client, so no extra clients are created per logger.
2026-08-05 14:54:31 -07:00
..
test_aiohttp_cleanup_closed.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_aiohttp_handler.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_aiohttp_so_keepalive.py fix(aiohttp): keep keep-alive connector config when a session is rebuilt (#34962) 2026-07-28 16:18:34 -07:00
test_aiohttp_transport.py fix(aiohttp): dispose recycled client sessions deterministically (#33428) 2026-07-31 16:48:08 +00:00
test_async_client_cleanup.py fix(async_client_cleanup): stop cleanup from resurrecting healed clients 2026-08-04 22:43:40 -07:00
test_credential_leak_prevention.py Litellm agent oss staging 05 11 2026 (#27733) 2026-05-13 14:09:12 -07:00
test_gemini_session_leak.py Fix __main__ exit bug, close litellm_async_client, restore global state 2026-03-14 18:14:42 -07:00
test_http_handler.py fix(langfuse): stop a collected httpx handler from closing a shared client (#35981) 2026-08-05 14:54:31 -07:00
test_llm_http_handler.py fix(anthropic): honor messages request timeout (#33418) 2026-07-15 14:37:48 -07:00
test_mock_transport.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00