Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dangling async tasks #7741

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

wtf-is-flying
Copy link

Create strong reference for all dangling async tasks

Not storing a strong reference to the task when calling asyncio.create_task() can cause the task to be garbage collected at any time, leading to a "Task was destroyed but it is pending!" error.

Relevant issues

Type

🐛 Bug Fix
🧹 Refactoring

Changes

This PR:

  • implements a create_background_task() util function (in litellm/litellm_core_utils/async_utils.py) that creates a task using asyncio.create_task(), stores a strong reference to it in a module-level defined set, and add a callback to discard the task from the set when it's done.
  • replace all calls to asyncio.create_task() that don't store a strong reference to the task with create_backgroud_task()

Copy link

vercel bot commented Jan 13, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 13, 2025 3:43pm

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.

1 participant