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

calling hass.services.async_register from a thread other than the event loop, may cause crash or data corruption #245

Open
532910 opened this issue Aug 7, 2024 · 11 comments

Comments

@532910
Copy link

532910 commented Aug 7, 2024

Detected that custom integration 'zha_toolkit' calls hass.services.async_register from a thread other than the event loop, which may cause Home Assistant to crash or data to corrupt. For more information, see https://developers.home-assistant.io/docs/asyncio_thread_safety/#hassservicesasync_register at custom_components/zha_toolkit/init.py, line 853: hass.services.async_register(, please report it to the author of the 'zha_toolkit' custom integration

@hahalj
Copy link

hahalj commented Aug 7, 2024

Same for me:

Logger: homeassistant.setup
Source: setup.py:404
First occurred: 9:39:51 AM (1 occurrences)
Last logged: 9:39:51 AM

Error during setup of component zha_toolkit
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/setup.py", line 404, in _async_setup_component
result = await task
^^^^^^^^^^
File "/config/custom_components/zha_toolkit/init.py", line 660, in async_setup
await hass.async_add_executor_job(register_services, hass)
File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/init.py", line 853, in register_services
hass.services.async_register(
File "/usr/src/homeassistant/homeassistant/core.py", line 2515, in async_register
self._hass.verify_event_loop_thread("hass.services.async_register")
File "/usr/src/homeassistant/homeassistant/core.py", line 463, in verify_event_loop_thread
frame.report_non_thread_safe_operation(what)
File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 225, in report_non_thread_safe_operation
report(
File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 159, in report
_report_integration(what, integration_frame, level, error_if_integration)
File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 197, in _report_integration
raise RuntimeError(
RuntimeError: Detected that custom integration 'zha_toolkit' calls hass.services.async_register from a thread other than the event loop, which may cause Home Assistant to crash or data to corrupt. For more information, see https://developers.home-assistant.io/docs/asyncio_thread_safety/#hassservicesasync_register at custom_components/zha_toolkit/init.py, line 853: hass.services.async_register(. Please report it to the author of the 'zha_toolkit' custom integration.

@jan-wern
Copy link

jan-wern commented Aug 7, 2024

Same Here

Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/setup.py", line 404, in _async_setup_component
result = await task
^^^^^^^^^^
File "/config/custom_components/zha_toolkit/init.py", line 660, in async_setup
await hass.async_add_executor_job(register_services, hass)
File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/init.py", line 853, in register_services
hass.services.async_register(
File "/usr/src/homeassistant/homeassistant/core.py", line 2515, in async_register
self._hass.verify_event_loop_thread("hass.services.async_register")
File "/usr/src/homeassistant/homeassistant/core.py", line 463, in verify_event_loop_thread
frame.report_non_thread_safe_operation(what)
File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 225, in report_non_thread_safe_operation
report(
File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 159, in report
_report_integration(what, integration_frame, level, error_if_integration)
File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 197, in _report_integration
raise RuntimeError(
RuntimeError: Detected that custom

@alexruffell
Copy link

alexruffell commented Aug 7, 2024

I have the same error. Are you all on the 2024.8 beta for HA Core? I wonder whether it is related to that and HA's apparent efforts to stamp out programming practices that weaken HA (my understanding from the errors, change logs, etc).

Edit: Not saying zha_toolkit was programmed poorly, but rather that HA is strengthening how things are done, thus requiring changes in integrations such as zha_toolkit.

@hahalj
Copy link

hahalj commented Aug 7, 2024

No I'm on 2024.7.4

Screenshot_20240807-174759

@jan-wern
Copy link

jan-wern commented Aug 7, 2024

I have the same error. Are you all on the 2024.8 beta for HA Core? I wonder whether it is related to that and HA's apparent efforts to stamp out programming practices that weaken HA (my understanding from the errors, change logs, etc).

Edit: Not saying zha_toolkit was programmed poorly, but rather that HA is strengthening how things are done, thus requiring changes in integrations such as zha_toolkit.

No, i am on Core 2024.7.4

@TheLion
Copy link

TheLion commented Aug 7, 2024

Also same error. Running 2024.7.4.

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 404, in _async_setup_component
    result = await task
             ^^^^^^^^^^
  File "/config/custom_components/zha_toolkit/__init__.py", line 660, in async_setup
    await hass.async_add_executor_job(register_services, hass)
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/zha_toolkit/__init__.py", line 853, in register_services
    hass.services.async_register(
  File "/usr/src/homeassistant/homeassistant/core.py", line 2515, in async_register
    self._hass.verify_event_loop_thread("hass.services.async_register")
  File "/usr/src/homeassistant/homeassistant/core.py", line 463, in verify_event_loop_thread
    frame.report_non_thread_safe_operation(what)
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 225, in report_non_thread_safe_operation
    report(
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 159, in report
    _report_integration(what, integration_frame, level, error_if_integration)
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 197, in _report_integration
    raise RuntimeError(
RuntimeError: Detected that custom integration 'zha_toolkit' calls hass.services.async_register from a thread other than the event loop, which may cause Home Assistant to crash or data to corrupt. For more information, see https://developers.home-assistant.io/docs/asyncio_thread_safety/#hassservicesasync_register at custom_components/zha_toolkit/__init__.py, line 853: hass.services.async_register(. Please report it to the author of the 'zha_toolkit' custom integration.

@PhilippeP62
Copy link

PhilippeP62 commented Aug 7, 2024

Same but on 2024.8

Solved with 1.1.16

@mdeweerd
Copy link
Owner

mdeweerd commented Aug 7, 2024

I've refactored some code - hopefully that's fine by the HomeAssistant team's rules. It start fine for me on 2024.07.4
v1.1.15 is released

@mdiazgoncalves
Copy link

The update fixed the previous error, but now I have this in the logs:

Logger: homeassistant.setup
Source: setup.py:271
First occurred: 23:45:47 (1 occurrences)
Last logged: 23:45:47

Setup failed for custom integration 'zha_toolkit': Requirements for zha_toolkit not found: ['pytz>=>2016.10'].

I'm on Core 2024.7.4

@alexruffell
Copy link

v1.1.16 is the latest version I saw and installed. The issue seems to have been fixed. I am running 2024.8 HA Core.

@mdiazgoncalves
Copy link

The update fixed the previous error, but now I have this in the logs:
Logger: homeassistant.setup Source: setup.py:271 First occurred: 23:45:47 (1 occurrences) Last logged: 23:45:47
Setup failed for custom integration 'zha_toolkit': Requirements for zha_toolkit not found: ['pytz>=>2016.10'].
I'm on Core 2024.7.4

1.1.16 have fixed the pytz error.

Thanks

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

8 participants