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

Detected blocking call #161

Open
c0mplex1 opened this issue Feb 1, 2025 · 12 comments
Open

Detected blocking call #161

c0mplex1 opened this issue Feb 1, 2025 · 12 comments
Labels
bug Something isn't working

Comments

@c0mplex1
Copy link
Contributor

c0mplex1 commented Feb 1, 2025

Hmmm, I just upgraded to version 0.7.3 and now I get this message:

Logger: homeassistant.util.loop
Source: util/loop.py:136
First occurred: 13:20:03 (1 occurrences)
Last logged: 13:20:03

2025-02-01 13:20:03.933 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to open with args ('/usr/local/bin/python3.13', 'rb') inside the event loop by custom integration 'zaptec' at custom_components/zaptec/api.py, line 326: receiver = servicebus_client.get_subscription_receiver( (offender: /usr/local/lib/python3.13/platform.py, line 204: with open(executable, 'rb') as f:), please report it to the author of the 'zaptec' custom integration
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 227, in <module>
    sys.exit(main())
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 213, in main
    exit_code = runner.run(runtime_conf)
  File "/usr/src/homeassistant/homeassistant/runner.py", line 154, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 707, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 678, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.13/asyncio/base_events.py", line 2033, in _run_once
    handle._run()
  File "/usr/local/lib/python3.13/asyncio/events.py", line 89, in _run
    self._context.run(self._callback, *self._args)
  File "/config/custom_components/zaptec/api.py", line 326, in _stream
    receiver = servicebus_client.get_subscription_receiver(
@vyveyp
Copy link

vyveyp commented Feb 1, 2025

Exact the same warning in my logfile.

@sveinse
Copy link
Collaborator

sveinse commented Feb 1, 2025

This is related to #116. Are you able to find out what version of the python package azure-servicebus you have installed in HA?

@sveinse sveinse added the bug Something isn't working label Feb 1, 2025
@sveinse
Copy link
Collaborator

sveinse commented Feb 1, 2025

On my system I found the easiest way is to use the Terminal in HA and enter:

➜ ~ docker exec -it homeassistant pip list |grep servicebus
azure-servicebus                 7.13.0

7.13.0 is the expected version and should contain the fix. I don't get this error on my system, so I'm trying to figure out if its the version of the servicebus that is incorrect, or if the problem still persists in the new version.

@sveinse
Copy link
Collaborator

sveinse commented Feb 1, 2025

Related to #154

@sveinse
Copy link
Collaborator

sveinse commented Feb 1, 2025

@c0mplex1

The cause for the issue is something down in a 3rd party package called azure-servicebus. I am unable to recreate this on my setup. I've confirmed that you are most likely running the right version of azure-servicebus (7.13.0), as the older versions fail more visibly with other errors. The challenge is that the error message dump from HA is incomplete, so I'm unable to drill down into the azure-servicebus to figure out what's really the cause here.

Would you mind describing your HA setup? Perhaps I can find a setup that's able to replicate your errors. How do you run HA? Via HaOS, native or virtual, container or direct. What kind of hardware and so on.

@c0mplex1
Copy link
Contributor Author

c0mplex1 commented Feb 1, 2025

@sveinse

The example you gave to get the azure-servicebus version doesn't work for me because I don't have HA running in Docker.
HA is installed on an Intel NUC7i3, 4Gb mem, 120Gb SSD. No other software is running.

@sveinse
Copy link
Collaborator

sveinse commented Feb 1, 2025

@c0mplex1

If you are running HAOS, it would have be using Docker, so I would assume you don't have that. How have you installed HA on the device? The docs I'm finding is only referring to HAOS: https://www.home-assistant.io/installation/generic-x86-64

@c0mplex1
Copy link
Contributor Author

c0mplex1 commented Feb 1, 2025

Sorry I wasn't clear enough.
Yes, I installed HAOS as described in https://www.home-assistant.io/installation/generic-x86-64#install-home-assistant-operating-system

@bdraco
Copy link

bdraco commented Feb 1, 2025

sdk/eventhub/azure-eventhub/azure/eventhub/_utils.py: platform_str = platform.platform()

@bdraco
Copy link

bdraco commented Feb 1, 2025

platform.platform() is not async safe and should not be called in the event loop.

await loop.run_in_executor(None, platform.platform) before should cache it tough. Still its technically a bug in the azure sdk that should be reported

https://github.com/python/cpython/blob/cf4c4ecc26c7e3b89f2e56893260a8a3319dab3d/Lib/platform.py#L1330

@sveinse
Copy link
Collaborator

sveinse commented Feb 2, 2025

@bdraco excellent find! Thank you.

The link to the aforementioned code here for reference: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventhub/azure-eventhub/azure/eventhub/_utils.py#L72

If platform.platform() is cached, then I think I have a theory why I'm unable to repro the error. Something else on my system is doing the call to it and caches it by the the time azure-servicebus is run, and thus no error.

Unfortunately there are quite many platform.platform() calls in their codebase. Moreso the call is buried deep into the callstack, so I do not see any immediate workaround from the calling side. We need to open a new issue at https://github.com/Azure/azure-sdk-for-python . The last issue I filed in that project took some time to fix, so I think the run_in_executor() will be a necessary workaround if we are to have a quick fix in place for Zaptec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants