Fix race condition when removing add-on (#5850)

When uninstalling an add-on, we schedule a task to reload the ingress
tokens. This scheduled task typically ends up running right after
clearing the add-on data with `self.sys_addons.data.uninstall(self)`
(since this task is doing I/O, the race is rather deterministic).

Let's make sure we reload the ingress tokens at the end. Also simply
execute reloading synchrounsly since this is a rather quick operation
and makes sure that errors would get attributed to the right add-on
uninstall operation.
This commit is contained in:
Stefan Agner 2025-04-29 16:14:33 +02:00 committed by GitHub
parent c1b45406d6
commit bc9e3eb95b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -846,9 +846,10 @@ class Addon(AddonModel):
await self.sys_ingress.update_hass_panel(self)
# Cleanup Ingress dynamic port assignment
need_ingress_token_cleanup = False
if self.with_ingress:
need_ingress_token_cleanup = True
await self.sys_ingress.del_dynamic_port(self.slug)
self.sys_create_task(self.sys_ingress.reload())
# Cleanup discovery data
for message in self.sys_discovery.list_messages:
@ -863,8 +864,12 @@ class Addon(AddonModel):
await service.del_service_data(self)
# Remove from addon manager
await self.sys_addons.data.uninstall(self)
self.sys_addons.local.pop(self.slug)
await self.sys_addons.data.uninstall(self)
# Cleanup Ingress tokens
if need_ingress_token_cleanup:
await self.sys_ingress.reload()
@Job(
name="addon_update",