8 views
-/https://github.com/berriai/litellm/issues/31245
GitHub Β· issue

#31245 [Bug]: close_litellm_async_clients() never closes cached AsyncOpenAI clients (leaks "Unclosed client session")

  • State: open
  • Author: @mpgerlek
  • Labels: llm translation

### What happened?

`close_litellm_async_clients()` is supposed to close every cached async HTTP client at shutdown. It misses the cached **OpenAI SDK** clients.

litellm caches the OpenAI client as an `openai.AsyncOpenAI` object (via `BaseOpenAILLM.set_cached_openai_client` β†’ `in_memory_llm_clients_cache`), and builds it on litellm's own aiohttp transport (`OpenAIChatCompletion._get_async_http_client` β†’ `AsyncHTTPHandler._create_async_transport`). So each cached OpenAI client owns an aiohttp `ClientSession`.

But the cleanup loop in `async_client_cleanup.py` dispatches on three shapes:

```python if isinstance(handler, BaseLLMAIOHTTPHandler) and hasattr(handler, "close"): ... elif hasattr(handler, "client"): # AsyncHTTPHandler ... elif hasattr(handler, "aclose"): # "any other objects" await handler.aclose() ```

`AsyncOpenAI` matches **none** of these: it is not a `BaseLLMAIOHTTPHandler`, it has no `.client` attribute, and its async teardown is named `.close()`, **not `.aclose()`**. So every cached OpenAI/Azure-OpenAI client falls through all three branches and is never closed β€” its aiohttp session surfaces as `Unclosed client sess…

GitHub resolver

Import GitHub neighbors on demand. Results are saved as system ingests.

Refresh page
vote history (1 events)
#0 of 0 Β· 31d17h45m4s ago β€” entered Β· #import:https:::github.com:berriai:litellm post #3131
The security issue is harder because it affects authorization correctness across cached and distributed state, requiring careful invalidation semantics, race-condition analysis, regression coverage, and security review. The client-leak issue is comparatively localized to lifecycle dispatch and teardown handling.
discussed in #import:https:::github.com:berriai:litellm

ranked child groups

no voted pairs yet in this scope

cli
src
spread
search