Skip to content

fix(litellm): close Token Spy client when worker is cancelled - #271

Merged
azilber merged 2 commits into
mainfrom
retry/pr-2642
Aug 10, 2026
Merged

fix(litellm): close Token Spy client when worker is cancelled#271
azilber merged 2 commits into
mainfrom
retry/pr-2642

Conversation

@azilber

@azilber azilber commented Aug 10, 2026

Copy link
Copy Markdown
Owner

Ports upstream Osmantic#2642: fix(litellm): close Token Spy client when worker is cancelled

Original: Osmantic#2642

Retry pass: conflicted with an earlier port from this run; hunks were disjoint so both were unioned. Lint/structural/legacy-token checked.

patil2001 and others added 2 commits August 7, 2026 22:59
ODSTokenSpyCallback._run() created an httpx.AsyncClient inside an async-with
each time the worker task was (re)created. Under cancellation (LiteLLM model
swap, gunicorn recycle, asyncio shutdown race) the __aexit__ could be skipped,
leaking sockets and file descriptors that compounded with every restart. Create
the client explicitly and close it in a finally block so aclose runs on both
cancellation and normal exit.
# Conflicts:
#	ods/extensions/services/litellm/ods_token_spy_callback.py
@azilber
azilber merged commit a056b17 into main Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants