Skip to content

Commit

Permalink
Don't check if Core is running to trigger rollback
Browse files Browse the repository at this point in the history
Currently we check for Core API access and that the state is running. If
this is not fulfilled within 5 minutes, we rollback to the previous
version.

It can take quite a while until Home Assistant Core is in state running.
In fact, after going through bootstrap, it can theoretically take
indefinitely (as in there is no timeout from Core side).

So to trigger rollback, rather than check the state to be running, just
check if the API is accessible in this case. This prevents spurious
rollbacks.
  • Loading branch information
agners committed Oct 31, 2023
1 parent a8f818f commit db446ea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions supervisor/homeassistant/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ async def get_core_state(self) -> dict[str, Any]:
"""Return Home Assistant core state."""
return await self._get_json("api/core/state")

async def check_api_state(self) -> bool:
async def check_api_state(self, check_running: bool = True) -> bool:
"""Return True if Home Assistant up and running."""
# Skip check on landingpage
if (
Expand All @@ -157,7 +157,9 @@ async def check_api_state(self) -> bool:
else:
data = await self.get_config()
# Older versions of home assistant does not expose the state
if data and data.get("state", "RUNNING") == "RUNNING":
if data:
if check_running:
return data.get("state", "RUNNING") == "RUNNING"
return True

return False
2 changes: 1 addition & 1 deletion supervisor/homeassistant/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ async def _block_till_run(self, version: AwesomeVersion) -> None:
break

# 2: Check if API response
if await self.sys_homeassistant.api.check_api_state():
if await self.sys_homeassistant.api.check_api_state(check_running=False):
_LOGGER.info("Detect a running Home Assistant instance")
self._error_state = False
return
Expand Down

0 comments on commit db446ea

Please sign in to comment.