From bc9e3eb95b257f829461e840d717b36e12ff756e Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Tue, 29 Apr 2025 16:14:33 +0200 Subject: [PATCH] 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. --- supervisor/addons/addon.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/supervisor/addons/addon.py b/supervisor/addons/addon.py index 8a3ade57c..338e0475a 100644 --- a/supervisor/addons/addon.py +++ b/supervisor/addons/addon.py @@ -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",