Cancel and await idle_start future if the task was canceled after an IMAP connection was lost#168662
Merged
Conversation
…MAP connection was lost
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a cleanup issue in the IMAP push (IDLE) loop where the idle_start() future could remain pending after a lost connection, leading to “Task was destroyed but it is pending!” warnings.
Changes:
- Track the
idle_start()future in the IMAP push loop and attempt to cancel/await it in afinallyblock to prevent leaked pending futures. - Add/adjust a regression test to assert the IDLE future is canceled after a simulated connection loss.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
homeassistant/components/imap/coordinator.py |
Adds finally cleanup to cancel/await the pending IDLE future after errors. |
tests/components/imap/test_init.py |
Extends the lost-connection push test to validate the IDLE cancellation path via logs. |
bdraco
reviewed
Apr 21, 2026
bdraco
reviewed
Apr 21, 2026
bdraco
reviewed
Apr 21, 2026
Co-authored-by: J. Nick Koston <nick@koston.org>
bdraco
reviewed
Apr 21, 2026
Co-authored-by: J. Nick Koston <nick@koston.org>
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
homeassistant/components/imap/coordinator.py:7
- Remove the unused
suppressimport (or use it) to avoid failing lint checks for an unused import.
from datetime import datetime, timedelta
bdraco
approved these changes
Apr 21, 2026
Contributor
Author
|
I still need some help to fix the code coverage for the new code. Optionally this is fixed later to allow the patch to be released. |
Contributor
Author
|
Discussed with @bdraco , desided to merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed change
If an IMAP server is awaited for push messages and the connection is lost, the IDLE command fails.
The future that was awaited still needs to be canceled.
This fix may solve issue #122809
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: