Repository navigation
fix(litellm): close shared cloud client - #2903
chopratejas merged 1 commit into
Conversation
PR governanceThis PR does not yet satisfy the required template fields:
Please update the PR body, or move the PR back to draft while it is still in progress. |
JerrettDavis
left a comment
There was a problem hiding this comment.
aclose() atomically detaches the shared client before awaiting closure, making repeated and concurrent cleanup calls idempotent and allowing the underlying async transport to drain correctly. No client is created on an unused/no-cloud path. The host-owned shutdown requirement is explicit in the API contract and tests cover initialized and no-op cases. The PR description checklist was corrected to reflect that no separate documentation file changed; broader CI has not run.
chopratejas
left a comment
There was a problem hiding this comment.
Maintainer review complete: aclose atomically detaches the shared client before awaiting closure, making no-op, repeated, and concurrent cleanup safe under the application-owned lifecycle contract. Merge after full CI. Public lifecycle documentation and a real-client regression remain useful nonblocking follow-ups.
Description
Adds an explicit, idempotent async cleanup lifecycle for the LiteLLM callback's shared cloud HTTP client.
Fixes #2894
Type of Change
Changes Made
HeadroomCallback.aclose()to close the lazily-createdhttpx.AsyncClientand clear its reference.Testing
pytest)ruff check .)mypy headroom)Test Output
Real Behavior Proof
httpx.AsyncClient.HeadroomCallback(api_key="hdr_test", api_url="http://127.0.0.1:<port>"), ran_cloud_compress()against it, saved the created client, awaitedcallback.aclose(), then awaitedcallback.aclose()again.aclose(), the callback reference becameNone, and repeated cleanup was harmless.httpxdependency; no native code or runtime network access is introduced by this fix.headroom._coreextension.Review Readiness
Checklist
aclose()is documented in its public docstring and the host owns shutdown sequencingCHANGELOG.md- it is generated by release-please from my Conventional Commit PR title.Screenshots (if applicable)
Not applicable.
Additional Notes
The callback exposes
aclose()for the host application's async shutdown lifecycle, matching the existing ASGI integration pattern.