From fc66997a368d9d6eb5c8fb5a7e07ac33fb109748 Mon Sep 17 00:00:00 2001 From: Tomek Wasilczyk Date: Wed, 2 Apr 2025 00:07:36 -0700 Subject: [PATCH] Fix warning about unfinished oauth tasks on shutdown (#141969) * Don't wait for OAuth token task on shutdown To reproduce the warning: 1. Start authentication with integration using OAuth (e.g. SmartThings) 2. When redirected to external login site, just close the page 3. Settings -> Restart Home Assistant * Clarify comment --------- Co-authored-by: Martin Hjelmare --- homeassistant/components/cloud/account_link.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/cloud/account_link.py b/homeassistant/components/cloud/account_link.py index 851d658f8e0..3c3d944d479 100644 --- a/homeassistant/components/cloud/account_link.py +++ b/homeassistant/components/cloud/account_link.py @@ -127,7 +127,11 @@ class CloudOAuth2Implementation(config_entry_oauth2_flow.AbstractOAuth2Implement flow_id=flow_id, user_input=tokens ) - self.hass.async_create_task(await_tokens()) + # It's a background task because it should be cancelled on shutdown and there's nothing else + # we can do in such case. There's also no need to wait for this during setup. + self.hass.async_create_background_task( + await_tokens(), name="Awaiting OAuth tokens" + ) return authorize_url