Proceed with startup if an integration setup blocks for more than 30m (#36082)

* Proceed with startup if an integration setup blocks for more than 30m

* Fix test location

* Fix log call

* naming

* revert

* do not shield from cancelation

* Adjust test since we now cancel when we hit the timeout
This commit is contained in:
J. Nick Koston authored and GitHub committed 2020-05-27 13:43:05 -05:00
1 parent 6fbc3b54bd
commit f626129e2b
4 files changed
+45 -7

No files matched your search

+18 -3
View File
@@ -19,6 +19,9 @@ DATA_SETUP = "setup_tasks"
DATA_DEPS_REQS = "deps_reqs_processed"
SLOW_SETUP_WARNING = 10
# Since a pip install can run, we wait
# 30 minutes to timeout
SLOW_SETUP_MAX_WAIT = 1800
def setup_component(hass: core.HomeAssistant, domain: str, config: ConfigType) -> bool:
@@ -167,16 +170,28 @@ async def _async_setup_component(
try:
if hasattr(component, "async_setup"):
result = await component.async_setup( # type: ignore
task = component.async_setup( # type: ignore
hass, processed_config
)
elif hasattr(component, "setup"):
result = await hass.async_add_executor_job(
component.setup, hass, processed_config # type: ignore
# This should not be replaced with hass.async_add_executor_job because
# we don't want to track this task in case it blocks startup.
task = hass.loop.run_in_executor(
None, component.setup, hass, processed_config # type: ignore
)
else:
log_error("No setup function defined.")
return False
result = await asyncio.wait_for(task, SLOW_SETUP_MAX_WAIT)
except asyncio.TimeoutError:
_LOGGER.error(
"Setup of %s is taking longer than %s seconds."
" Startup will proceed without waiting any longer.",
domain,
SLOW_SETUP_MAX_WAIT,
)
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)