Files
litellm/tests
Cole McIntosh 4db25169d2 Fix: Properly close aiohttp client sessions to prevent resource leaks (#12251)
* Fix: Properly close aiohttp client sessions to prevent resource leaks (#12107)

- Add close() method to BaseLLMAIOHTTPHandler to properly close aiohttp ClientSession
- Create async_client_cleanup module with utility functions to close all cached async clients
- Register automatic cleanup at exit via atexit hook
- Export close_litellm_async_clients() function for manual cleanup
- Add comprehensive tests to verify resource cleanup

This fixes the "Unclosed client session" and "Unclosed connector" warnings when using acompletion with Gemini and other models that use aiohttp.

Fixes #12107

* Fix: Remove unused import to satisfy linter

* Fix: Extend cleanup to handle AsyncHTTPHandler instances used by Gemini

The original implementation only cleaned up BaseLLMAIOHTTPHandler instances,
but Gemini/Vertex AI providers use AsyncHTTPHandler objects which contain
httpx clients with aiohttp transports.

This commit extends the cleanup function to:
- Handle AsyncHTTPHandler instances by accessing their internal client
- Close both the aiohttp transport and httpx client
- Add generic fallback for any objects with aclose method

This properly fixes the resource leak warnings for all provider types.
2025-07-09 09:25:17 -07:00
..
2025-07-04 18:30:50 -07:00
2025-07-03 16:13:44 -07:00
2025-06-14 13:51:52 -07:00
2025-07-01 20:33:21 -07:00
2025-06-20 12:09:45 -07:00
2025-05-26 22:06:53 -07:00

In total litellm runs 1000+ tests

[02/20/2025] Update:

To make it easier to contribute and map what behavior is tested,

we've started mapping the litellm directory in tests/litellm

This folder can only run mock tests.