mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-13 04:06:33 +00:00
Avoid lingering tasks when using background backup tasks (#5518)
When a backup tasks is run in background, but actually has an error early the secondary event task to release the callee is lingering around still, ultimately leading to a "Task was destroyed but it is pending!" asyncio error. Make sure we cancel the event task in case the backup returns early.
This commit is contained in:
parent
e72c5a037b
commit
61b37877be
@ -296,13 +296,18 @@ class APIBackups(CoreSysAttributes):
|
||||
BusEvent.SUPERVISOR_STATE_CHANGE, release_on_freeze
|
||||
)
|
||||
try:
|
||||
await asyncio.wait(
|
||||
event_task = self.sys_create_task(event.wait())
|
||||
_, pending = await asyncio.wait(
|
||||
(
|
||||
backup_task,
|
||||
self.sys_create_task(event.wait()),
|
||||
event_task,
|
||||
),
|
||||
return_when=asyncio.FIRST_COMPLETED,
|
||||
)
|
||||
# It seems backup returned early (error or something), make sure to cancel
|
||||
# the event task to avoid "Task was destroyed but it is pending!" errors.
|
||||
if event_task in pending:
|
||||
event_task.cancel()
|
||||
return (backup_task, job.uuid)
|
||||
finally:
|
||||
self.sys_bus.remove_listener(listener)
|
||||
|
Loading…
x
Reference in New Issue
Block a user