Breina / idrac_power_monitor

HomeAssistant integration to monitor the power of a server through its iDrac's Redfish API
17 stars 17 forks source link

Non-thread-safe operations causing HA crash since 2024.4.0 #13

Closed cjr222 closed 2 months ago

cjr222 commented 2 months ago

RuntimeError: Non-thread-safe operation invoked on an event loop other than the current one 2024-04-13 07:34:13.851 ERROR (MainThread) [homeassistant] Error doing job: Task was destroyed but it is pending!: File "/usr/local/lib/python3.12/threading.py", line 1030, in _bootstrap self._bootstrap_inner() File "/usr/local/lib/python3.12/threading.py", line 1073, in _bootstrap_inner self.run() File "/usr/local/lib/python3.12/threading.py", line 1010, in run self._target(*self._args, *self._kwargs) File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 92, in _worker work_item.run() 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/idrac_power/idrac_rest.py", line 109, in update_thermals callback(self.thermal_values) File "/config/custom_components/idrac_power/sensor.py", line 128, in update_value self.async_schedule_update_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1233, in async_schedule_update_ha_state self.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 998, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1181, in _async_write_ha_state hass.states.async_set( File "/usr/src/homeassistant/homeassistant/core.py", line 2181, in async_set self._bus._async_fire( # pylint: disable=protected-access File "/usr/src/homeassistant/homeassistant/core.py", line 1459, in _async_fire self._hass.async_add_hass_job(job, event) File "/usr/src/homeassistant/homeassistant/core.py", line 686, in async_add_hass_job task = self.loop.create_task(hassjob.target(args), name=hassjob.name) File "/usr/local/lib/python3.12/asyncio/base_events.py", line 457, in create_task task = tasks.Task(coro, loop=self, name=name, context=context)

Breina commented 2 months ago

Thanks for the report, that does seem to come from this integration indeed.

Just updated my staging environment to 2024.4.3 and didn't see any issues. Can you please give me the steps leading up to this error?

Breina commented 2 months ago

Should be fixed. Please test v1.2.6 and report back.

cjr222 commented 2 months ago

It appears to be fixed. I upgraded just your integration and didn't touch HA version yet, and it started much faster and is not crashing. Thank you!