Periodically log when integrations are taking a while to setup (#36208)
* Periodicly log when intergrations are taking a while to setup When one or more intergrations are taking a while to setup it is hard to determine which one is the cause. We can help narrow this down for the user with a periodic log message about which domains are still waiting to be setup every 30s. * 30 -> 60 per discussion * only log when the integration is actually doing setup * reduce, fix race in test
This commit is contained in:
1 parent
e1fd14e00a
commit
5183c40b23
3 files changed
+72
-2
No files matched your search
@@ -10,11 +10,13 @@ from homeassistant.config import async_notify_setup_error
|
||||
from homeassistant.const import EVENT_COMPONENT_LOADED, PLATFORM_FORMAT
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTR_COMPONENT = "component"
|
||||
|
||||
DATA_SETUP_STARTED = "setup_started"
|
||||
DATA_SETUP = "setup_tasks"
|
||||
DATA_DEPS_REQS = "deps_reqs_processed"
|
||||
|
||||
@@ -155,6 +157,7 @@ async def _async_setup_component(
|
||||
|
||||
start = timer()
|
||||
_LOGGER.info("Setting up %s", domain)
|
||||
hass.data.setdefault(DATA_SETUP_STARTED, {})[domain] = dt_util.utcnow()
|
||||
|
||||
if hasattr(component, "PLATFORM_SCHEMA"):
|
||||
# Entity components have their own warning
|
||||
@@ -181,6 +184,7 @@ async def _async_setup_component(
|
||||
)
|
||||
else:
|
||||
log_error("No setup function defined.")
|
||||
hass.data[DATA_SETUP_STARTED].pop(domain)
|
||||
return False
|
||||
|
||||
result = await asyncio.wait_for(task, SLOW_SETUP_MAX_WAIT)
|
||||
@@ -191,10 +195,12 @@ async def _async_setup_component(
|
||||
domain,
|
||||
SLOW_SETUP_MAX_WAIT,
|
||||
)
|
||||
hass.data[DATA_SETUP_STARTED].pop(domain)
|
||||
return False
|
||||
except Exception: # pylint: disable=broad-except
|
||||
_LOGGER.exception("Error during setup of component %s", domain)
|
||||
async_notify_setup_error(hass, domain, integration.documentation)
|
||||
hass.data[DATA_SETUP_STARTED].pop(domain)
|
||||
return False
|
||||
finally:
|
||||
end = timer()
|
||||
@@ -204,12 +210,14 @@ async def _async_setup_component(
|
||||
|
||||
if result is False:
|
||||
log_error("Integration failed to initialize.")
|
||||
hass.data[DATA_SETUP_STARTED].pop(domain)
|
||||
return False
|
||||
if result is not True:
|
||||
log_error(
|
||||
f"Integration {domain!r} did not return boolean if setup was "
|
||||
"successful. Disabling component."
|
||||
)
|
||||
hass.data[DATA_SETUP_STARTED].pop(domain)
|
||||
return False
|
||||
|
||||
# Flush out async_setup calling create_task. Fragile but covered by test.
|
||||
@@ -224,6 +232,7 @@ async def _async_setup_component(
|
||||
)
|
||||
|
||||
hass.config.components.add(domain)
|
||||
hass.data[DATA_SETUP_STARTED].pop(domain)
|
||||
|
||||
# Cleanup
|
||||
if domain in hass.data[DATA_SETUP]:
|
||||
|
||||
Reference in new issue
Block a user