Athozs / hass-additional-ca

Add private Certificate Authority or self-signed certificate into Home Assistant to access 3rd-party service with TLS/SSL.
MIT License
29 stars 4 forks source link

'Detected blocking call to open inside the event loop' warnings in logs at HA start #7

Closed 35gh closed 4 months ago

35gh commented 4 months ago

Describe the issue

Since update to HAOS 12.3 and/or 2024.6, I got those warnings in logs after HA start up: Detected blocking call to open inside the event loop by custom integration 'additional_ca' at custom_components/

Describe your setup (please complete the following information):

YAML configuration extract

additional_ca:
    my_awesome_ca: ca-cert.crt

environment_variable:
    REQUESTS_CA_BUNDLE: /etc/ssl/certs/ca.crt

Logs

Enregistreur: homeassistant.util.loop
Source: util/loop.py:84
S'est produit pour la première fois: 00:03:40 (7 occurrences)
Dernier enregistrement: 00:03:40

    Detected blocking call to open inside the event loop by custom integration 'additional_ca' at custom_components/additional_ca/__init__.py, line 149: shutil.copyfile(certifi_bundle_path, certifi_backup) (offender: /usr/local/lib/python3.12/shutil.py, line 260: with open(src, 'rb') as fsrc:), please create a bug report at https://github.com/Athozs/hass-additional-ca/issues 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 223, in <module> sys.exit(main()) File "/usr/src/homeassistant/homeassistant/__main__.py", line 209, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, in _run_once handle._run() File "/usr/local/lib/python3.12/asyncio/events.py", line 88, 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 402, in _async_setup_component result = await task File "/config/custom_components/additional_ca/__init__.py", line 53, in async_setup await update_certifi_certificates(hass, config) File "/config/custom_components/additional_ca/__init__.py", line 149, in update_certifi_certificates shutil.copyfile(certifi_bundle_path, certifi_backup)
    Detected blocking call to open inside the event loop by custom integration 'additional_ca' at custom_components/additional_ca/__init__.py, line 149: shutil.copyfile(certifi_bundle_path, certifi_backup) (offender: /usr/local/lib/python3.12/shutil.py, line 262: with open(dst, 'wb') as fdst:), please create a bug report at https://github.com/Athozs/hass-additional-ca/issues 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 223, in <module> sys.exit(main()) File "/usr/src/homeassistant/homeassistant/__main__.py", line 209, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, in _run_once handle._run() File "/usr/local/lib/python3.12/asyncio/events.py", line 88, 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 402, in _async_setup_component result = await task File "/config/custom_components/additional_ca/__init__.py", line 53, in async_setup await update_certifi_certificates(hass, config) File "/config/custom_components/additional_ca/__init__.py", line 149, in update_certifi_certificates shutil.copyfile(certifi_bundle_path, certifi_backup)
    Detected blocking call to open inside the event loop by custom integration 'additional_ca' at custom_components/additional_ca/__init__.py, line 154: with open(certifi_bundle_path, "r") as f: (offender: /config/custom_components/additional_ca/__init__.py, line 154: with open(certifi_bundle_path, "r") as f:), please create a bug report at https://github.com/Athozs/hass-additional-ca/issues 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 223, in <module> sys.exit(main()) File "/usr/src/homeassistant/homeassistant/__main__.py", line 209, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, in _run_once handle._run() File "/usr/local/lib/python3.12/asyncio/events.py", line 88, 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 402, in _async_setup_component result = await task File "/config/custom_components/additional_ca/__init__.py", line 53, in async_setup await update_certifi_certificates(hass, config) File "/config/custom_components/additional_ca/__init__.py", line 154, in update_certifi_certificates with open(certifi_bundle_path, "r") as f:
    Detected blocking call to open inside the event loop by custom integration 'additional_ca' at custom_components/additional_ca/__init__.py, line 168: with open(additional_ca_fullpath, "r") as f: (offender: /config/custom_components/additional_ca/__init__.py, line 168: with open(additional_ca_fullpath, "r") as f:), please create a bug report at https://github.com/Athozs/hass-additional-ca/issues 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 223, in <module> sys.exit(main()) File "/usr/src/homeassistant/homeassistant/__main__.py", line 209, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, in _run_once handle._run() File "/usr/local/lib/python3.12/asyncio/events.py", line 88, 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 402, in _async_setup_component result = await task File "/config/custom_components/additional_ca/__init__.py", line 53, in async_setup await update_certifi_certificates(hass, config) File "/config/custom_components/additional_ca/__init__.py", line 168, in update_certifi_certificates with open(additional_ca_fullpath, "r") as f:
    Detected blocking call to open inside the event loop by custom integration 'additional_ca' at custom_components/additional_ca/__init__.py, line 179: with open(certifi_bundle_path, "a") as cafile: (offender: /config/custom_components/additional_ca/__init__.py, line 179: with open(certifi_bundle_path, "a") as cafile:), please create a bug report at https://github.com/Athozs/hass-additional-ca/issues 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 223, in <module> sys.exit(main()) File "/usr/src/homeassistant/homeassistant/__main__.py", line 209, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 190, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete self.run_forever() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever self._run_once() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, in _run_once handle._run() File "/usr/local/lib/python3.12/asyncio/events.py", line 88, 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 402, in _async_setup_component result = await task File "/config/custom_components/additional_ca/__init__.py", line 53, in async_setup await update_certifi_certificates(hass, config) File "/config/custom_components/additional_ca/__init__.py", line 179, in update_certifi_certificates with open(certifi_bundle_path, "a") as cafile:

Additional context

Warnings appear after HA has started, everything works after that.

Athozs commented 4 months ago

Hi @35gh , thanks your using Additional CA, I can see the same issue with Home Assistant 2024.6. It seems that other custom integrations are facing the same. Issues have been opened at https://github.com/home-assistant/core/issues?q=is%3Aopen+detected+blocking+call I'll wait and see what they say.

mundschenk-at commented 4 months ago

I think you are not supposed to do blocking IO from within the event loop. 2024.6.x simply improved the detection of such issues, so it now pops up for lots of integrations. Here's an article regarding timezone handling, but the principle is probably similar for other types of IO.

The forum also has some advice how to handle the issue in general.

accessiblepixel commented 4 months ago

Hi, yes, just thought I'd pop here that I've got the issue too, but lucky (hopefully?) it's just a warning and hasn't affected any functionality for me yet.

Thanks for the work on additional-ca, it's been invaluable to getting stuff to communicate over SSL <3

IgnacioHR commented 4 months ago

Just subscribed, I’m affected too, good luck

Athozs commented 4 months ago

Hello, I pushed a fix in release 0.2.3, tested with HAOS 12.3 (Home Assistant 2024.6.2) Could you give a feedback ?

rwjack commented 4 months ago

I'm not getting the warning anymore with 0.2.3

35gh commented 4 months ago

It works for me as well, no more warning in logs after restart. Thank you!

accessiblepixel commented 4 months ago

How do I install the updated version? It hasn't come up in HACS as an update? (Sorry I'm a bit new to hacs and things)

Again thanks for the amazing work on additional-ca, it's made things way less a chore <3

35gh commented 4 months ago

In HACS > Integrations > Additional CA click on the 3 dots on the top right, then Redownload.

accessiblepixel commented 4 months ago

Thanks for the tip for the future. Though it came up as an update today. @35gh :) Much obliged.