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

Bug: calls device_registry.async_update_device from a thread other than the event loop #427

Open
2 of 4 tasks
ancjsd opened this issue Oct 20, 2024 · 0 comments
Open
2 of 4 tasks

Comments

@ancjsd
Copy link

ancjsd commented Oct 20, 2024

Describe the bug
A clear and concise description of what the bug is.

Receiving the following runtime error in Home Assistant:

Detected that custom integration 'hass_agent' calls device_registry.async_update_device 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/#device_registry

Here's the complete Home Assistant log containing the error:

Exception in updated when handling msg on 'hass.agent/devices/xxx': '{"serial_number":"xxxxxxxxxxxxxxxxxxxxx","device":{"identifiers":"hass.agent-NUC","manufacturer":"HASS.Agent Team","model":"Microsoft Windows NT 10.0.22631.0","name":"xxx","sw_version":"2.0.1"},"apis":{"notifications":true,"media_player":false}}' Traceback (most recent call last): File "/config/custom_components/hass_agent/init.py", line 144, in updated update_device_info(hass, entry, payload) File "/config/custom_components/hass_agent/init.py", line 29, in update_device_info device_registry.async_get_or_create( File "/usr/src/homeassistant/homeassistant/helpers/device_registry.py", line 834, in async_get_or_create device = self.async_update_device( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/device_registry.py", line 1066, in async_update_device self.hass.verify_event_loop_thread("device_registry.async_update_device") File "/usr/src/homeassistant/homeassistant/core.py", line 462, in verify_event_loop_thread frame.report_non_thread_safe_operation(what) File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 229, in report_non_thread_safe_operation report( File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 163, in report _report_integration(what, integration_frame, level, error_if_integration) File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 201, in _report_integration raise RuntimeError( RuntimeError: Detected that custom integration 'hass_agent' calls device_registry.async_update_device 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/#device_registryasync_update_device at custom_components/hass_agent/init.py, line 29: device_registry.async_get_or_create(. Please report it to the author of the 'hass_agent' custom integration.

Misc info (please complete the following information):

  • Windows build (ideally screenshot/info of winver.exe output): Windows 11 Pro Version 23H2 (OS Build 22631.4317)
  • Windows' UI language: en-IS
  • HASS.Agent version: 2.01

Please check what's applicable (multiple answers possible):

  • Installed via installer
  • Installed manually
  • Problem occurs in HASS.Agent --PRESUMABLY IN HASS.AGENT GIVEN THE ERROR MESSAGE, BUT I'M USING THE SATELLITE SERVICE
  • Problem occurs in Satellite Service

Logs

HASS.Agent log:

2024-10-20 11:22:45.418 -08:00 [INF] [MAIN] HASS.Agent version: 2.0.1
2024-10-20 11:22:45.424 -08:00 [INF] [SETTINGS] Config storage path: C:\Users\xxxx\AppData\Local\HASS.Agent\Client\config
2024-10-20 11:22:45.596 -08:00 [INF] [SETTINGS] Configuration loaded
2024-10-20 11:22:45.600 -08:00 [INF] [LOCALIZATION] Selected UI culture: [en] English
2024-10-20 11:22:46.104 -08:00 [INF] [RADIOMGR] Ready
2024-10-20 11:22:48.160 -08:00 [INF] [INTERNALSENSORS] Ready
2024-10-20 11:22:50.965 -08:00 [ERR] [VIRTDESKT] Error initializing Virtual Desktop Manager, your Windows version may be unsupported
2024-10-20 11:22:50.977 -08:00 [INF] [SETTINGS_QUICKACTIONS] Config not found, no entities loaded
2024-10-20 11:22:50.978 -08:00 [INF] [SETTINGS_COMMANDS] Config not found, no entities loaded
2024-10-20 11:22:50.980 -08:00 [INF] [SETTINGS_SENSORS] Config not found, no entities loaded
2024-10-20 11:22:50.985 -08:00 [INF] [HOTKEY] Completed bind for global quickaction hotkey
2024-10-20 11:22:51.044 -08:00 [INF] [LOCALAPI] Disabled
2024-10-20 11:22:51.095 -08:00 [INF] [MQTT] Identifying as device: NUC
2024-10-20 11:22:51.146 -08:00 [INF] [MQTT] Connecting ..
2024-10-20 11:22:51.154 -08:00 [INF] [SERVICE] Local install path: C:\Program Files\HASS.Agent\Service
2024-10-20 11:22:51.157 -08:00 [INF] [MEDIA] Disabled
2024-10-20 11:22:51.201 -08:00 [INF] [MQTT] Connected
2024-10-20 11:22:51.297 -08:00 [INF] [NOTIFIER] Ready
2024-10-20 11:22:51.595 -08:00 [INF] [HASS_API] Home Assistant version: 2024.10.3
2024-10-20 11:22:51.804 -08:00 [INF] [HASS_API] System connected with http://192.168.xx.xx:8123
2024-10-20 11:22:53.165 -08:00 [INF] [MQTT] Initial registration completed

Satellite Service Log:

2024-10-20 11:21:23.449 -08:00 [INF] [MAIN] Version: 2.0.1.0
2024-10-20 11:21:23.498 -08:00 [INF] [MAIN] Service started, initializing ..
2024-10-20 11:21:23.701 -08:00 [INF] [MAIN] Running as a service, initializing lifetime manager
2024-10-20 11:21:23.783 -08:00 [INF] [LIFETIMEMANAGER] Initialized
2024-10-20 11:21:23.876 -08:00 [INF] [WORKER] Startup completed, commencing execution ..
2024-10-20 11:21:26.242 -08:00 [INF] [SETTINGS] Config storage path: C:\Program Files\HASS.Agent\Service\config
2024-10-20 11:21:26.336 -08:00 [INF] [SETTINGS] Configuration loaded
2024-10-20 11:21:26.341 -08:00 [INF] [SETTINGS] MQTT configuration loaded
2024-10-20 11:21:26.350 -08:00 [INF] Application started. Hosting environment: Production; Content root path: C:\Program Files\HASS.Agent\Service
2024-10-20 11:21:26.367 -08:00 [INF] [SETTINGS_COMMANDS] Loaded 5 entities
2024-10-20 11:21:26.379 -08:00 [INF] [SETTINGS_SENSORS] Loaded 1 entities
2024-10-20 11:21:26.383 -08:00 [INF] [MQTT] Identifying as device: NUC-satellite
2024-10-20 11:21:26.399 -08:00 [INF] [MQTT] Connecting ..
2024-10-20 11:21:26.403 -08:00 [INF] [RPCMANAGER] Listening
2024-10-20 11:22:35.855 -08:00 [WRN] [MQTT] Disconnected: UnspecifiedError
2024-10-20 11:22:35.871 -08:00 [FTL] [MQTT] Error while connecting: Error while connecting with host '192.168.xx.xx:1883'.
MQTTnet.Exceptions.MqttCommunicationException: Error while connecting with host '192.168.xx.xx:1883'.
---> System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it.
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at System.Net.Sockets.Socket.g__WaitForConnectWithCancellation|277_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
at MQTTnet.Implementations.CrossPlatformSocket.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at MQTTnet.Implementations.CrossPlatformSocket.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
at MQTTnet.Implementations.MqttTcpChannel.ConnectAsync(CancellationToken cancellationToken)
at MQTTnet.Adapter.MqttChannelAdapter.ConnectAsync(CancellationToken cancellationToken)
at MQTTnet.Client.MqttClient.ConnectInternal(IMqttChannelAdapter channelAdapter, CancellationToken cancellationToken)
at MQTTnet.Client.MqttClient.ConnectAsync(MqttClientOptions options, CancellationToken cancellationToken)
at MQTTnet.Client.MqttClient.ConnectAsync(MqttClientOptions options, CancellationToken cancellationToken)
at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.ReconnectIfRequiredAsync(CancellationToken cancellationToken)
2024-10-20 11:22:41.041 -08:00 [INF] [MQTT] Connected
2024-10-20 11:22:42.704 -08:00 [INF] [MQTT] Initial registration completed

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

1 participant