home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.98k stars 30.17k forks source link

sia reads codes file in the event loop which does blocking I/O #119058

Open miguelangel-nubla opened 3 months ago

miguelangel-nubla commented 3 months ago

The problem

In HA version 2024.6.0 the logs get flooded with warnings about a blocking call made to sia_codes.json

What version of Home Assistant Core has the issue?

core-2024.6.0

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

SIA Alarm Systems

Link to integration documentation on our website

https://www.home-assistant.io/integrations/sia/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2024-06-07 11:46:39.282 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to open with args ('/usr/local/lib/python3.12/site-packages/pysiaalarm/data/sia_codes.json', 'rb') in /usr/local/lib/python3.12/site-packages/pkg_resources/__init__.py, line 1693: return open(self._fn(self.module_path, resource_name), 'rb') inside the event loop
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 672, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1988, 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/local/lib/python3.12/site-packages/pysiaalarm/aio/server.py", line 54, in handle_line
    event = self.parse_and_check_event(data)
  File "/usr/local/lib/python3.12/site-packages/pysiaalarm/base_server.py", line 64, in parse_and_check_event
    event = SIAEvent.from_line(line, self.accounts)
  File "/usr/local/lib/python3.12/site-packages/pysiaalarm/event.py", line 161, in from_line
    return SIAEvent(
  File "<string>", line 28, in __init__
  File "/usr/local/lib/python3.12/site-packages/pysiaalarm/event.py", line 266, in __post_init__
    self.set_sia_code()
  File "/usr/local/lib/python3.12/site-packages/pysiaalarm/event.py", line 106, in set_sia_code
    self.sia_code = _load_sia_codes().get(self.code)  # pylint: disable=E1101
  File "/usr/local/lib/python3.12/site-packages/pysiaalarm/data/data.py", line 44, in _load_sia_codes
    data = _load_data(FILE_SIA_CODES)
  File "/usr/local/lib/python3.12/site-packages/pysiaalarm/data/data.py", line 38, in _load_data
    stream = pkg_resources.resource_stream(__name__, file)
  File "/usr/local/lib/python3.12/site-packages/pkg_resources/__init__.py", line 1187, in resource_stream
    return get_provider(package_or_requirement).get_resource_stream(
  File "/usr/local/lib/python3.12/site-packages/pkg_resources/__init__.py", line 1693, in get_resource_stream
    return open(self._fn(self.module_path, resource_name), 'rb')

Additional information

No response

home-assistant[bot] commented 3 months ago

Hey there @eavanvalkenburg, mind taking a look at this issue as it has been labeled with an integration (sia) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `sia` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign sia` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


sia documentation sia source (message by IssueLinks)

DaN66O commented 3 months ago

I have the same problem

aperezva commented 3 months ago

The same error, any feedback to solve it?

miguelangel-nubla commented 3 months ago

@eavanvalkenburg do you still maintain this?

aperezva commented 3 months ago

It seems nobody support a official integration. Really?

bdraco commented 3 months ago

For the most part, integration maintainers are volunteers working on HA in their spare time. It can take while for someone to have free time to pickup issues.

aperezva commented 3 months ago

I know. And it s wonderful this efforts.

The only doubt I have is an official integration has a minimum level of support.

I can understand this situation in a Hacs or no. Official integrations but I don’t know if it s the same situation in a official integrations.

Anybody knows?

And please, thanks a lot to the people who invest 1 minute to make our lives easier

frli4797 commented 3 months ago

This problem seems to stem from pysiaalarm using pkg_resources, which then uses blocking io. I guess, as pkg_resources this should be migrated to importlib as the former is deprecated.

However, that might not fix this issue as the maintainer of said package would still have to implement some unblocking io here, using aiofiles or something similar. Not really sure what that would look like, but there's a similar issue fixed here.

DaN66O commented 3 weeks ago

@eavanvalkenburg do you still maintain this?

aperezva commented 3 weeks ago

For the most part, integration maintainers are volunteers working on HA in their spare time. It can take while for someone to have free time to pickup issues.

@bdraco after 2 months of this issue, it seems nobody is maintaining this integration. Any alternatives to it?

Teunhen commented 1 week ago

Same problem here.