Skip to content
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

Don't block Supervisor entry setup with refreshing updates #109809

Merged
merged 3 commits into from Feb 6, 2024
Merged

Conversation

frenck
Copy link
Member

@frenck frenck commented Feb 6, 2024

Proposed change

On startup, the hassio integration will refresh all updates, which can take quite a bit of time (e.g., pulling all git repositories of add-ons). This main cause a global timeout on the first stage:

2024-02-05 13:13:03.763 WARNING (MainThread) [homeassistant.bootstrap] Waiting on integrations to complete setup: hassio
2024-02-05 13:14:01.155 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Hassio for hassio
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 442, in async_setup
result = await component.async_setup_entry(hass, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/hassio/__init__.py", line 634, in async_setup_entry
await coordinator.async_config_entry_first_refresh()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 278, in async_config_entry_first_refresh
await self._async_refresh(
File "/usr/src/homeassistant/homeassistant/components/hassio/__init__.py", line 1007, in _async_refresh
await self.hassio.refresh_updates()
File "/usr/src/homeassistant/homeassistant/components/hassio/handler.py", line 39, in _wrapper
data = await funct(*argv, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/hassio/handler.py", line 574, in send_command
request = await self.websession.request(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 605, in _request
await resp.start(conn)
File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 966, in start
message, payload = await protocol.read() # type: ignore[union-attr]
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/aiohttp/streams.py", line 622, in read
await self._waiter
asyncio.exceptions.CancelledError: Global task timeout
2024-02-05 13:14:01.184 WARNING (MainThread) [homeassistant.bootstrap] Setup timed out for stage 1 - moving forward

We don't have to block the setup for this; So, this PR removes this call from the startup. Information will be available a bit later (also the Supervisor does update that info on a schedule as well).

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works. (already covered)

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@home-assistant
Copy link

home-assistant bot commented Feb 6, 2024

Hey there @home-assistant/supervisor, mind taking a look at this pull request as it has been labeled with an integration (hassio) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of hassio can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign hassio Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@frenck frenck added this to the 2024.2.0 milestone Feb 6, 2024
Comment on lines -924 to -930
assert refresh_updates_mock.call_count == 0

# There is a REQUEST_REFRESH_DELAYs cooldown on the debouncer
async_fire_time_changed(
hass, dt_util.now() + timedelta(seconds=REQUEST_REFRESH_DELAY)
)
await hass.async_block_till_done()
Copy link
Member Author

@frenck frenck Feb 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was actually not correct / not functional this way.
Corrected now.

@bdraco
Copy link
Member

bdraco commented Feb 6, 2024

Tested with various sensors enabled and disabled and restarting on two different production instances. No obvious regressions observed

@frenck frenck merged commit db16b73 into dev Feb 6, 2024
53 checks passed
@frenck frenck deleted the frenck-2024-0202 branch February 6, 2024 21:34
@github-actions github-actions bot locked and limited conversation to collaborators Feb 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants