zha-toolkit icon indicating copy to clipboard operation
zha-toolkit copied to clipboard

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

Open 532910 opened this issue 1 year ago • 11 comments

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

532910 avatar Aug 07 '24 03:08 532910

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.

hahalj avatar Aug 07 '24 07:08 hahalj

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

jan-wern avatar Aug 07 '24 08:08 jan-wern

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.

alexruffell avatar Aug 07 '24 15:08 alexruffell

No I'm on 2024.7.4

Screenshot_20240807-174759

hahalj avatar Aug 07 '24 15:08 hahalj

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

jan-wern avatar Aug 07 '24 15:08 jan-wern

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.

TheLion avatar Aug 07 '24 17:08 TheLion

Same but on 2024.8

Solved with 1.1.16

PhilippeP62 avatar Aug 07 '24 21:08 PhilippeP62

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

mdeweerd avatar Aug 07 '24 22:08 mdeweerd

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

mdiazgoncalves avatar Aug 07 '24 22:08 mdiazgoncalves

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.

alexruffell avatar Aug 07 '24 23:08 alexruffell

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

mdiazgoncalves avatar Aug 08 '24 05:08 mdiazgoncalves