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

Make sure Futures are cleaned up correctly #96

Merged
merged 3 commits into from
Oct 13, 2023

Conversation

jbouwh
Copy link
Contributor

@jbouwh jbouwh commented Aug 3, 2023

As maintainer of the imap integration in Home Assistant we noticed users see Errors in their logs like:
Error doing job: Task was destroyed but it is pending
This is caused when a future of task is not held in memory and Garbage collection cancels the job. at a few places in the code asyncio.ensure_future() is used without storing a reference to the Future. When executions takes longer it can be garbage collected before it is done or canceled causing the error.

So calling asyncio.ensure_future starts a background task, but because this task is not stored, linked or referenced, the garbage collection might pick up the task and cancell it. According to https://docs.python.org/3/library/asyncio-task.html#asyncio.create_task we need to make sure we remove or discard the task when it is done.

See also logs linked with:
home-assistant/core#95239

@jbouwh jbouwh changed the title Make sure Futures are not cleaned up correctly Make sure Futures are cleaned up correctly Aug 3, 2023
@bamthomas bamthomas merged commit e6fed53 into bamthomas:master Oct 13, 2023
@jbouwh jbouwh deleted the discard-future-when-done branch October 14, 2023 08:08
@jbouwh
Copy link
Contributor Author

jbouwh commented Jun 7, 2024

@bamthomas This was merged more than 8 months ago. Is it possible to brew a new release so we can bump to it in Home Assistant?

@bamthomas
Copy link
Owner

Of course sorry about that

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