litellm/litellm
Ishaan Jaff 503eb2fd4c
fix: don't close HTTP/SDK clients on LLMClientCache eviction (#22925)
* fix: don't close HTTP/SDK clients on LLMClientCache eviction

Removing the _remove_key override that eagerly called aclose()/close()
on evicted clients. Evicted clients may still be held by in-flight
streaming requests; closing them causes:

  RuntimeError: Cannot send a request, as the client has been closed.

This is a regression from commit fb72979432. Clients that are no longer
referenced will be garbage-collected naturally. Explicit shutdown cleanup
happens via close_litellm_async_clients().

Fixes production crashes after the 1-hour cache TTL expires.

* test: update LLMClientCache unit tests for no-close-on-eviction behavior

Flip the assertions: evicted clients must NOT be closed. Replace
test_remove_key_closes_async_client → test_remove_key_does_not_close_async_client
and equivalents for sync/eviction paths.

Add test_remove_key_removes_plain_values for non-client cache entries.
Remove test_background_tasks_cleaned_up_after_completion (no more _background_tasks).
Remove test_remove_key_no_event_loop variant that depended on old behavior.

* test: add e2e tests for OpenAI SDK client surviving cache eviction

Add two new e2e tests using real AsyncOpenAI clients:
- test_evicted_openai_sdk_client_stays_usable: verifies size-based eviction
  doesn't close the client
- test_ttl_expired_openai_sdk_client_stays_usable: verifies TTL expiry
  eviction doesn't close the client

Both tests sleep after eviction so any create_task()-based close would
have time to run, making the regression detectable.

Also expand the module docstring to explain why the sleep is required.

* docs(AGENTS.md): add rule — never close HTTP/SDK clients on cache eviction

* docs(CLAUDE.md): add HTTP client cache safety guideline
2026-03-05 12:00:38 -08:00
..
a2a_protocol fix: replace assert with RuntimeError and fix return type annotation 2026-03-05 06:38:38 -03:00
anthropic_interface
assistants
batch_completion
batches fix(mypy): resolve type errors across 9 files 2026-03-05 06:58:20 -03:00
caching fix: don't close HTTP/SDK clients on LLMClientCache eviction (#22925) 2026-03-05 12:00:38 -08:00
completion_extras
containers
endpoints/speech/speech_to_completion_bridge
evals
experimental_mcp_client
files
fine_tuning Update litellm/fine_tuning/main.py 2026-03-05 06:45:31 -03:00
google_genai
images
integrations fix: downgrade WebSearch logs from info to debug to reduce production noise 2026-03-05 18:58:40 +01:00
interactions
litellm_core_utils Merge pull request #22866 from mubashir1osmani/feat/bedrock-mantle-provider-clean 2026-03-05 18:24:00 +05:30
llms Merge pull request #22679 from giulio-leone/fix/websearch-thinking-constraint 2026-03-06 00:49:17 +05:30
ocr
passthrough fix(passthrough): propagate Azure 429/5xx errors in async streaming instead of silent HTTP 200 (#22913) 2026-03-05 10:12:43 -08:00
proxy feat(proxy): include user_email in jwt upsert user creation (#22915) 2026-03-05 10:55:11 -08:00
proxy_auth
rag
realtime_api
rerank_api
responses
router_strategy fix: complexity_router crashes on list-format message content (OpenAI multi-part messages) (#22761) 2026-03-04 16:18:49 -08:00
router_utils
search
secret_managers
skills
types fix(merge): resolve conflict with main in cost_tracking_settings 2026-03-05 14:01:07 -03:00
vector_store_files
vector_stores
videos
__init__.py Merge pull request #22866 from mubashir1osmani/feat/bedrock-mantle-provider-clean 2026-03-05 18:24:00 +05:30
_lazy_imports_registry.py Merge pull request #22866 from mubashir1osmani/feat/bedrock-mantle-provider-clean 2026-03-05 18:24:00 +05:30
_lazy_imports.py
_logging.py
_redis.py
_service_logger.py
_uuid.py
_version.py
anthropic_beta_headers_config.json
anthropic_beta_headers_manager.py
blog_posts.json
budget_manager.py
constants.py
cost_calculator.py
cost.json
exceptions.py
main.py Merge pull request #22866 from mubashir1osmani/feat/bedrock-mantle-provider-clean 2026-03-05 18:24:00 +05:30
model_prices_and_context_window_backup.json Merge pull request #22916 from BerriAI/litellm_gpt-5.4_day_0 2026-03-05 23:41:35 +05:30
mypy.ini
policy_templates_backup.json
provider_endpoints_support_backup.json
py.typed
router.py
scheduler.py
timeout.py
utils.py Merge pull request #22866 from mubashir1osmani/feat/bedrock-mantle-provider-clean 2026-03-05 18:24:00 +05:30