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

Govee Integration Causing Blocking Call Inside Event Loop in Home Assistant #189

Open
l33cuj3s opened this issue Nov 20, 2024 · 4 comments

Comments

@l33cuj3s
Copy link

l33cuj3s commented Nov 20, 2024

Description:

I am encountering issues with the govee custom integration in Home Assistant, which appears to be making a blocking call inside the event loop. This issue is causing warnings and could be leading to stability problems within my setup, potentially affecting other functionalities, such as Google Assistant integrations. The specific warning and traceback are provided below.

Home Assistant Version:

  • Core 2024.11.2
  • Supervisor 2024.11.2
  • Operating System 13.2
  • Frontend 20241106.2

Custom Integration Version:

  • Govee Integration Version: 2023.11.1

Installation Method:

  • Home Assistant OS

Description of Problem:

Upon reviewing the Home Assistant logs, I found multiple warnings related to the govee custom integration, specifically indicating that it makes a blocking call (load_verify_locations) inside the event loop. This kind of blocking behavior could potentially affect the overall performance and stability of Home Assistant.

Here is the relevant log snippet:

2024-11-20 17:32:17.527 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to load_verify_locations with args (<ssl.SSLContext object at 0xffff555d27d0>, '/usr/local/lib/python3.12/site-packages/certifi/cacert.pem', None, None) inside the event loop by custom integration 'govee' at custom_components/govee/__init__.py, line 53: hub = await Govee.create(
(offender: /usr/local/lib/python3.12/ssl.py, line 708: context.load_verify_locations(cafile, capath, cadata)), please create a bug report at https://github.com/LaggAt/hacs-govee/issues

For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#load_verify_locations

The log shows that the blocking operation is called at custom_components/govee/__init__.py, line 53. This blocking behavior can impact the Home Assistant event loop and should ideally be refactored to use an asynchronous approach.

Steps to Reproduce:

  1. Set up the Govee custom integration through HACS.
  2. Restart Home Assistant.
  3. Observe the logs for warnings during startup.

Expected Behavior:

  • The Govee integration should not make any blocking calls during the event loop, and there should be no warnings in the logs related to blocking operations.

Actual Behavior:

  • A warning is generated indicating a blocking call made by the Govee integration, which may impact overall stability.

Relevant Logs:

2024-11-20 17:32:17.527 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to load_verify_locations with args (<ssl.SSLContext object at 0xffff555d27d0>, '/usr/local/lib/python3.12/site-packages/certifi/cacert.pem', None, None) inside the event loop by custom integration 'govee' at custom_components/govee/__init__.py, line 53: hub = await Govee.create(
(offender: /usr/local/lib/python3.12/ssl.py, line 708: context.load_verify_locations(cafile, capath, cadata))

Additional Information:

  • The warning recommends creating an issue report, which is why I'm reaching out here.
  • Please let me know if you need any additional information, such as specific versions or configurations.

Suggested Solution:

  • Refactor the load_verify_locations call to be non-blocking, or use an async-compatible approach as recommended in the Home Assistant developer documentation.
@zed1thou
Copy link

I have a similar issue with blocking call to load verify locations.
Relevant logs*

Logger: homeassistant.util.loop
Source: util/loop.py:136
First occurred: 09:51:36 (2 occurrences)
Last logged: 09:51:37

Detected blocking call to load_verify_locations with args (<ssl.SSLContext object at 0x7f78c735c0>, '/usr/local/lib/python3.13/site-packages/certifi/cacert.pem', None, None) inside the event loop by custom integration 'govee' at custom_components/govee/__init__.py, line 53: hub = await Govee.create( (offender: /usr/local/lib/python3.13/ssl.py, line 717: context.load_verify_locations(cafile, capath, cadata)), please create a bug report at https://github.com/LaggAt/hacs-govee/issues For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#load_verify_locations Traceback (most recent call last): File "<frozen runpy>", line 198, in _run_module_as_main File "<frozen runpy>", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/__main__.py", line 227, in <module> sys.exit(main()) File "/usr/src/homeassistant/homeassistant/__main__.py", line 213, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 154, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.13/asyncio/base_events.py", line 708, in run_until_complete self.run_forever() File "/usr/local/lib/python3.13/asyncio/base_events.py", line 679, in run_forever self._run_once() File "/usr/local/lib/python3.13/asyncio/base_events.py", line 2027, in _run_once handle._run() File "/usr/local/lib/python3.13/asyncio/events.py", line 89, in _run self._context.run(self._callback, *self._args) File "/usr/src/homeassistant/homeassistant/setup.py", line 165, in async_setup_component result = await _async_setup_component(hass, domain, config) File "/usr/src/homeassistant/homeassistant/setup.py", line 461, in _async_setup_component await asyncio.gather( File "/usr/src/homeassistant/homeassistant/setup.py", line 463, in <genexpr> create_eager_task( File "/usr/src/homeassistant/homeassistant/util/async_.py", line 45, in create_eager_task return Task(coro, loop=loop, name=name, eager_start=True) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 788, in async_setup_locked await self.async_setup(hass, integration=integration) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 551, in async_setup await self.__async_setup_with_context(hass, integration) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 640, in __async_setup_with_context result = await component.async_setup_entry(hass, self) File "/config/custom_components/govee/__init__.py", line 53, in async_setup_entry hub = await Govee.create(
Detected blocking call to open with args ('/config/govee_learning.yaml',) inside the event loop by custom integration 'govee' at custom_components/govee/learning_storage.py, line 28: learned_dict = load_yaml(self._config_dir + LEARNING_STORAGE_YAML) (offender: /usr/src/homeassistant/homeassistant/util/yaml/loader.py, line 167: with open(fname, encoding="utf-8") as conf_file:), please create a bug report at https://github.com/LaggAt/hacs-govee/issues For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#open Traceback (most recent call last): File "<frozen runpy>", line 198, in _run_module_as_main File "<frozen runpy>", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/__main__.py", line 227, in <module> sys.exit(main()) File "/usr/src/homeassistant/homeassistant/__main__.py", line 213, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 154, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.13/asyncio/base_events.py", line 708, in run_until_complete self.run_forever() File "/usr/local/lib/python3.13/asyncio/base_events.py", line 679, in run_forever self._run_once() File "/usr/local/lib/python3.13/asyncio/base_events.py", line 2027, in _run_once handle._run() File "/usr/local/lib/python3.13/asyncio/events.py", line 89, in _run self._context.run(self._callback, *self._args) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 788, in async_setup_locked await self.async_setup(hass, integration=integration) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 551, in async_setup await self.__async_setup_with_context(hass, integration) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 640, in __async_setup_with_context result = await component.async_setup_entry(hass, self) File "/config/custom_components/govee/__init__.py", line 64, in async_setup_entry _, err = await hub.get_devices() File "/usr/local/lib/python3.13/site-packages/govee_api_laggat/govee_api_laggat.py", line 312, in get_devices _, err_api = await self._api.get_devices() File "/usr/local/lib/python3.13/site-packages/govee_api_laggat/api.py", line 244, in get_devices learning_infos = await self._govee._learning_storage._read_cached() File "/usr/local/lib/python3.13/site-packages/govee_api_laggat/learning_storage.py", line 30, in _read_cached self._learned_info = await self.read() File "/config/custom_components/govee/learning_storage.py", line 28, in read learned_dict = load_yaml(self._config_dir + LEARNING_STORAGE_YAML)

@intrepidsilence
Copy link

Same here 2024.12.5

@sisimomo
Copy link

sisimomo commented Jan 4, 2025

Same here on 2025.01.1

2025-01-03 19:39:18.176 INFO (MainThread) [custom_components.hacs] 
-------------------------------------------------------------------
HACS (Home Assistant Community Store)

Version: 2.0.1
This is a custom integration
If you have any issues with this you need to open an issue here:
https://github.com/hacs/integration/issues
-------------------------------------------------------------------

2025-01-03 19:39:18.187 INFO (MainThread) [homeassistant.setup] Setting up systemmonitor
2025-01-03 19:39:18.187 INFO (MainThread) [homeassistant.setup] Setup of domain systemmonitor took 0.00 seconds
2025-01-03 19:39:18.200 INFO (MainThread) [homeassistant.setup] Setting up speedtestdotnet
2025-01-03 19:39:18.200 INFO (MainThread) [homeassistant.setup] Setup of domain speedtestdotnet took 0.00 seconds
2025-01-03 19:39:18.207 INFO (MainThread) [homeassistant.setup] Setting up homeassistant_alerts
2025-01-03 19:39:18.207 INFO (MainThread) [homeassistant.setup] Setup of domain homeassistant_alerts took 0.00 seconds
2025-01-03 19:39:18.240 INFO (MainThread) [homeassistant.setup] Setting up govee
2025-01-03 19:39:18.240 INFO (MainThread) [homeassistant.setup] Setup of domain govee took 0.00 seconds
2025-01-03 19:39:18.255 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to load_verify_locations with args (<ssl.SSLContext object at 0x7f39613d2180>, '/usr/local/lib/python3.13/site-packages/certifi/cacert.pem', None, None) inside the event loop by custom integration 'govee' at custom_components/govee/__init__.py, line 53: hub = await Govee.create( (offender: /usr/local/lib/python3.13/ssl.py, line 717: context.load_verify_locations(cafile, capath, cadata)), please create a bug report at https://github.com/LaggAt/hacs-govee/issues
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#load_verify_locations
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 227, in <module>
    sys.exit(main())
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 213, in main
    exit_code = runner.run(runtime_conf)
  File "/usr/src/homeassistant/homeassistant/runner.py", line 154, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 707, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 678, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 2033, in _run_once
    handle._run()
  File "/usr/local/lib/python3.13/asyncio/events.py", line 89, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/setup.py", line 165, in async_setup_component
    result = await _async_setup_component(hass, domain, config)
  File "/usr/src/homeassistant/homeassistant/setup.py", line 461, in _async_setup_component
    await asyncio.gather(
  File "/usr/src/homeassistant/homeassistant/setup.py", line 463, in <genexpr>
    create_eager_task(
  File "/usr/src/homeassistant/homeassistant/util/async_.py", line 45, in create_eager_task
    return Task(coro, loop=loop, name=name, eager_start=True)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 788, in async_setup_locked
    await self.async_setup(hass, integration=integration)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 551, in async_setup
    await self.__async_setup_with_context(hass, integration)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 640, in __async_setup_with_context
    result = await component.async_setup_entry(hass, self)
  File "/config/custom_components/govee/__init__.py", line 53, in async_setup_entry
    hub = await Govee.create(

@ifmael
Copy link

ifmael commented Jan 24, 2025

Same 2025.1.2 , nd also

2025-01-19 01:01:22.263 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to open with args ('/config/govee_learning.yaml',) inside the event loop by custom integration 'govee' at custom_components/govee/learning_storage.py, line 28: learned_dict = load_yaml(self._config_dir + LEARNING_STORAGE_YAML) (offender: /usr/src/homeassistant/homeassistant/util/yaml/loader.py, line 167: with open(fname, encoding="utf-8") as conf_file:), please create a bug report at https://github.com/LaggAt/hacs-govee/issues
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#open
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 227, in <module>
    sys.exit(main())
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 213, in main
    exit_code = runner.run(runtime_conf)
  File "/usr/src/homeassistant/homeassistant/runner.py", line 154, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 707, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 678, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 2033, in _run_once
    handle._run()
  File "/usr/local/lib/python3.13/asyncio/events.py", line 89, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 788, in async_setup_locked
    await self.async_setup(hass, integration=integration)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 551, in async_setup
    await self.__async_setup_with_context(hass, integration)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 640, in __async_setup_with_context
    result = await component.async_setup_entry(hass, self)
  File "/config/custom_components/govee/__init__.py", line 64, in async_setup_entry
    _, err = await hub.get_devices()
  File "/usr/local/lib/python3.13/site-packages/govee_api_laggat/govee_api_laggat.py", line 312, in get_devices
    _, err_api = await self._api.get_devices()
  File "/usr/local/lib/python3.13/site-packages/govee_api_laggat/api.py", line 244, in get_devices
    learning_infos = await self._govee._learning_storage._read_cached()
  File "/usr/local/lib/python3.13/site-packages/govee_api_laggat/learning_storage.py", line 30, in _read_cached
    self._learned_info = await self.read()
  File "/config/custom_components/govee/learning_storage.py", line 28, in read
    learned_dict = load_yaml(self._config_dir + LEARNING_STORAGE_YAML)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants