zxdavb / ramses_cc

HA integration for CH/DHW and HVAC systems that use the RAMSES II RF protocol
GNU General Public License v3.0
71 stars 16 forks source link

Detected blocking call to open inside the event loop by custom integration 'ramses_cc' #192

Closed bluediamond1984 closed 2 weeks ago

bluediamond1984 commented 3 months ago

This warning is shown in the log after upgrading from 0.31.11 to 0.41.20 on Home Assistant 2024.6.1. It happens on every reboot of Home Assistant. The integration is working perfectly.

home-assistant_2024-06-09T08-52-58.955Z.log

Could be the same solution as https://github.com/home-assistant/core/issues/118403. This warning is also in the logs.

zxdavb commented 2 months ago

This is the relevant Traceback:

2024-06-09 10:38:45.598 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to open inside the event loop by custom integration 'ramses_cc' at custom_components/ramses_cc/broker.py, line 175: return Gateway( 
(offender: /usr/local/lib/python3.12/site-packages/serial/tools/list_ports_linux.py, line 84: 
with open(os.path.join(*args)) as f:), 
please create a bug report at https://github.com/zxdavb/ramses_cc/issues

Traceback (most recent call last):
...
  File "/config/custom_components/ramses_cc/broker.py", line 126, in async_setup
    self.client = self._create_client(merged_schema)
  File "/config/custom_components/ramses_cc/broker.py", line 175, in _create_client
    return Gateway(
zxdavb commented 2 months ago

In ramses_rf, Gateway, which is a subclass of Engine, we have is_hgi80():

class Engine:
    def __init__(
        self,
        port_name: str | None,
        input_file: TextIOWrapper | None = None,
...
    ) -> None:
...
        if input_file:
            self._disable_sending = True
        elif port_name:
            is_hgi80(port_name)  # raise an exception if the port is not found
zxdavb commented 2 months ago

I believe it is fixed.

mushi commented 1 month ago

I believe it is fixed.

Thanks! Is the fix released? I'm on version 0.41.23 and I see this in my logs:

2024-08-06 15:14:42.838 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to open with args ('/config/packet.log', 'a') inside the event loop by custom integration 'ramses_cc' at custom_components/ramses_cc/broker.py, line 175: return Gateway( (offender: /usr/local/lib/python3.12/logging/__init__.py, line 1263: return open_func(self.baseFilename, self.mode,), please create a bug report at https://github.com/zxdavb/ramses_cc/issues
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#open
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 674, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 641, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1990, 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 167, in async_setup_component
    result = await _async_setup_component(hass, domain, config)
  File "/usr/src/homeassistant/homeassistant/setup.py", line 449, in _async_setup_component
    await asyncio.gather(
  File "/usr/src/homeassistant/homeassistant/setup.py", line 451, in <genexpr>
    create_eager_task(
  File "/usr/src/homeassistant/homeassistant/util/async_.py", line 37, in create_eager_task
    return Task(coro, loop=loop, name=name, eager_start=True)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 734, in async_setup_locked
    await self.async_setup(hass, integration=integration)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 586, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/config/custom_components/ramses_cc/__init__.py", line 89, in async_setup_entry
    await broker.async_setup()
  File "/config/custom_components/ramses_cc/broker.py", line 126, in async_setup
    self.client = self._create_client(merged_schema)
  File "/config/custom_components/ramses_cc/broker.py", line 175, in _create_client
    return Gateway(
zxdavb commented 2 weeks ago

Thanks! Is the fix released? I'm on version 0.41.23 and I see this in my logs:

This is a different issue. Needs fixing, though.

Is still an issue in 0.42.0.

zxdavb commented 2 weeks ago

This is fixed with a change to the underlying library: https://github.com/zxdavb/ramses_rf/commit/4910218e9e2f714892c73094b200dd014880cc57

It will be included in 0.40.1 and later.