Closed gjohansson-ST closed 2 years ago
Tried to figure out which function was doing something but didn't so far...
Does this happen on dev
after #73387 or only in 2022.6/pre dev?
Let me try it again as I'm not sure if my testing was before or after merging of the linked PR.
I rebased my dev now with all the last changes and verified the commit from #73387 is included. Still same outcome.
I can replicate this problem. It happens when switching off polling but seems fine after a restart. Is that what you are seeing as well?
entry_id: "374f06d20134f0d14ef428aa63c98217"
id: 34
pref_disable_new_entities: false
pref_disable_polling: false
type: "config_entries/update"
Seems to be a problem with this config api
So I think whats happening is the entry is updated here
Then the reload listener fires and reloads https://github.com/home-assistant/core/blob/a77ea1c39003d2be959c8e73fc8f4e7521a09e84/homeassistant/components/sql/__init__.py#L12
And config also reloads https://github.com/home-assistant/core/blob/a77ea1c39003d2be959c8e73fc8f4e7521a09e84/homeassistant/components/config/config_entries.py#L343
So its yet another reload race 😢
2022-06-14 21:49:11 WARNING (MainThread) [homeassistant.config_entries] finished unload of DB Size -- sensor
2022-06-14 21:49:11 WARNING (MainThread) [homeassistant.config_entries] finished unload of DB Size -- sql
2022-06-14 21:49:11 WARNING (MainThread) [homeassistant.config_entries] Set unload of DB Size to ConfigEntryState.NOT_LOADED -- sql
2022-06-14 21:49:11 WARNING (MainThread) [homeassistant.config_entries] async_forward_entry_setup: ConfigEntryState.LOADED
2022-06-14 21:49:11 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.sql
2022-06-14 21:49:11 WARNING (MainThread) [homeassistant.components.sql.sensor] called async_add_entities
2022-06-14 21:49:11 WARNING (MainThread) [homeassistant.config_entries] finished unload of DB Size -- sensor
2022-06-14 21:49:11 WARNING (MainThread) [homeassistant.config_entries] finished unload of DB Size -- sql
2022-06-14 21:49:11 WARNING (MainThread) [homeassistant.config_entries] Set unload of DB Size to ConfigEntryState.NOT_LOADED -- sql
2022-06-14 21:49:11 WARNING (MainThread) [homeassistant.config_entries] async_forward_entry_setup: ConfigEntryState.LOADED
2022-06-14 21:49:11 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.sql
2022-06-14 21:49:11 WARNING (MainThread) [homeassistant.components.sql.sensor] called async_add_entities
2022-06-14 21:49:11 ERROR (MainThread) [homeassistant.components.sensor] Platform sql does not generate unique IDs. ID 374f06d20134f0d14ef428aa63c98217 already exists - ignoring sensor.db_size
So the entity is still updating from the first reload when the second reload starts happening
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.config_entries] finished unload of DB Size -- sensor
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.config_entries] finished unload of DB Size -- sql
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.config_entries] Set unload of DB Size to ConfigEntryState.NOT_LOADED -- sql
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.config_entries] async_forward_entry_setup: ConfigEntryState.LOADED
2022-06-14 22:15:17 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.sql
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.components.sql.sensor] called async_add_entities
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.config_entries] finished unload of DB Size -- sensor
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.helpers.entity_platform] _async_add_entity: <Entity DB Size> -- entry_state: ConfigEntryState.LOADED
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.helpers.entity_platform] _async_add_entity finished add_to_platform_start: <Entity DB Size: None> -- entry_state: ConfigEntryState.LOADED
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.helpers.entity_platform] _async_add_entity calling update_before_add: <Entity DB Size: None> -- entry_state: ConfigEntryState.LOADED
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.config_entries] finished unload of DB Size -- sql
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.config_entries] Set unload of DB Size to ConfigEntryState.NOT_LOADED -- sql
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.config_entries] async_forward_entry_setup: ConfigEntryState.LOADED
2022-06-14 22:15:17 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.sql
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.helpers.entity_platform] _async_add_entity finished update_before_add: <Entity DB Size: 540049408> -- entry_state: ConfigEntryState.LOADED
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.helpers.entity_platform] _async_add_entity finished registry check: <Entity DB Size: 540049408> -- entry_state: ConfigEntryState.LOADED
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.helpers.entity_platform] _async_add_entity finished Generate entity ID: <Entity DB Size: 540049408> -- entry_state: ConfigEntryState.LOADED
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.helpers.entity_platform] _async_add_entity finished valid_entity_id: <Entity DB Size: 540049408> -- entry_state: ConfigEntryState.LOADED
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.helpers.entity_platform] last chance _async_add_entity: <Entity DB Size: 540049408> -- entry_state: ConfigEntryState.LOADED
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.components.sql.sensor] called async_add_entities
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.helpers.entity_platform] _async_add_entity: <Entity DB Size> -- entry_state: ConfigEntryState.LOADED
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.helpers.entity_platform] _async_add_entity finished add_to_platform_start: <Entity DB Size: None> -- entry_state: ConfigEntryState.LOADED
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.helpers.entity_platform] _async_add_entity calling update_before_add: <Entity DB Size: None> -- entry_state: ConfigEntryState.LOADED
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.helpers.entity_platform] _async_add_entity finished update_before_add: <Entity DB Size: 540049408> -- entry_state: ConfigEntryState.LOADED
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.helpers.entity_platform] _async_add_entity finished registry check: <Entity DB Size: 540049408> -- entry_state: ConfigEntryState.LOADED
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.helpers.entity_platform] _async_add_entity finished Generate entity ID: <Entity DB Size: 540049408> -- entry_state: ConfigEntryState.LOADED
2022-06-14 22:15:17 WARNING (MainThread) [homeassistant.helpers.entity_platform] _async_add_entity finished valid_entity_id: <Entity DB Size: 540049408> -- entry_state: ConfigEntryState.LOADED
2022-06-14 22:15:17 ERROR (MainThread) [homeassistant.components.sensor] Platform sql does not generate unique IDs. ID 374f06d20134f0d14ef428aa63c98217 already exists - ignoring sensor.db_size
Maybe we need some type of reload debouncer
I can't think of any other way to solve this
At least some type of guard to prevent reloading more than once every 10-20s as thats unlikely to ever end up with a good result
I can replicate this problem. It happens when switching off polling but seems fine after a restart. Is that what you are seeing as well?
Yepp. Seems also some guard should be in place here so check if a reload is already happening in one way or another.
The problem is the reload is done at that point as reloads are already done under a lock. The entity is still setting up from the previous reload which happens in a task which happens asynchronously and is is not awaited from to the config entry setup.
Candidates to fix this are the debouncer we use in the coordinator and the ratelimiter we use for templates
Most of the UI messages say entities will appear in 30s so that seems like the right cooldown period
We want these to fire immediately and then cool down for 30s before allowing another reload
The problem
Not entirely sure where the problem is but if you for a config entry turn off polling it tries to create entities twice and thereby complaining about not unique id. Therefore services such as
update_entity
does not work any longerTurn off polling from config entry system options
What version of Home Assistant Core has the issue?
dev
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant Core
Integration causing the issue
core
Link to integration documentation on our website
No response
Diagnostics information
No response
Example YAML snippet
No response
Anything in the logs that might be useful for us?
No response
Additional information
No response