From bb6f3bc830d663ab02d4a014e8194382fdff238d Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Fri, 29 Dec 2023 10:04:16 +0100 Subject: [PATCH] Fix missing await when running shutdown jobs (#106632) --- homeassistant/core.py | 2 +- tests/test_core.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/homeassistant/core.py b/homeassistant/core.py index 72287fb81ce..51cb3d4e496 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -889,7 +889,7 @@ class HomeAssistant: continue tasks.append(task_or_none) if tasks: - asyncio.gather(*tasks, return_exceptions=True) + await asyncio.gather(*tasks, return_exceptions=True) except asyncio.TimeoutError: _LOGGER.warning( "Timed out waiting for shutdown jobs to complete, the shutdown will" diff --git a/tests/test_core.py b/tests/test_core.py index 5f5be1b05db..90b87068a5d 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -2605,6 +2605,9 @@ async def test_shutdown_job(hass: HomeAssistant) -> None: evt = asyncio.Event() async def shutdown_func() -> None: + # Sleep to ensure core is waiting for the task to finish + await asyncio.sleep(0.01) + # Set the event evt.set() job = HassJob(shutdown_func, "shutdown_job")