-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
Hold a lock to pre 8000 vent concurrent setup of config entries #116482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
If something triggers a config entry to reload while we are still in the setup of the underlying component/integration the lock was not held because async_setup_component does not hold the reload lock. Rename the reload lock to setup lock.
if entry.domain not in self.hass.config.components: | ||
# If the component is not loaded, just load it as | ||
# the config entry will be loaded as well. We need | ||
# to do this before holding the lock to avoid a | ||
# deadlock. | ||
await async_setup_component(self.hass, entry.domain, self._hass_config) | ||
return entry.state is ConfigEntryState.LOADED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is exactly what self.async_setup(entry_id)
does, but we need to do it without holding the lock since async_setup_component
will hold the lock
testing this on my production now. I want to add an explicit test for the case where we have a long setup time and we trigger a reload |
I also need to profile this |
profile is good pushed to all production |
…t_setup' into hold_lock_to_prevent_concurrent_setup
I've beat this up as much as I can on my production and dev envs. |
Proposed change
If something triggers a config entry to reload while we are still in the setup of the underlying component/integration, the lock was not held because
async_setup_component
does not hold the reload lock. We only had a lock to prevent concurrent reloads, and there wasn't anything to handle a reload during startup. The common case is that there is a config entry update listener and it triggers a reload because something during its setup updates its config entry data.This has been a problem for a long time but it wasn't fast enough until 2024.5.x for us to see this happen on a regular basis.
config_entries.async_remove
should also probably hold the lock to unload the entry and remove it but I didn't want to make that change in this PR as the problem is far less likely to happenRename the reload lock to setup lock.
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requiremen 8000 ts_all
..coveragerc
.To help with the load of incoming pull requests: