alexa_media_player: WARNING: Detected blocking call to load_verify_locations with args (,) inside the event loop by custom integration 'alexa_media
Describe the bug
This is not a bug! The warning messages should be addressed though so as to not impact performance in the HA event loop.
To Reproduce
HA 2024.9.x now detects blocking calls (which have always been this way)
Expected behavior
No warning messages
System details
- Home Assistant version: 2024.9.0
- alexa_media version (from
const.pyor HA startup log): 4.12.11 - alexapy version (from
pip show alexapyin homeasssistant container or HA startup log): 1.28.2 - Is Amazon 2FA/2SV enabled <!—We will not debug login issues if unanswered—> (y/n): y
- Amazon Domain: amazon.it
Debug Logs (alexa_media & alexapy) 2024-09-04 19:37:06.401 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to load_verify_locations with args (<ssl.SSLContext object at 0x7f155dedfd50>, ‘/usr/local/lib/python3.12/site-packages/certifi/cacert.pem’, None, None) inside the event loop by custom integration ‘alexa_media’ at custom_components/alexa_media/init.py, line 340: AlexaLogin( (offender: /usr/local/lib/python3.12/ssl.py, line 708: context.load_verify_locations(cafile, capath, cadata)), please create a bug report at https://github.com/alandtse/alexa_media_player/issues For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#load_verify_locations 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 189, 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 165, in async_setup_component result = await _async_setup_component(hass, domain, config) File “/usr/src/homeassistant/homeassistant/setup.py”, line 461, in async_setup_component await asyncio.gather( File “/usr/src/homeassistant/homeassistant/setup.py”, line 463, in <genexpr> create_eager_task( File "/usr/src/homeassistant/homeassistant/util/async.py", line 45, in create_eager_task return Task(coro, loop=loop, name=name, eager_start=True) File “/usr/src/homeassistant/homeassistant/config_entries.py”, line 752, in async_setup_locked await self.async_setup(hass, integration=integration) File “/usr/src/homeassistant/homeassistant/config_entries.py”, line 604, in async_setup result = await component.async_setup_entry(hass, self) File “/config/custom_components/alexa_media/init.py”, line 340, in async_setup_entry AlexaLogin(
2024-09-04 19:37:06.627 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to open with args (PosixPath(‘/config/.storage/alexa_media.XXX@XX.pickle’),) inside the event loop by custom integration ‘alexa_media’ at custom_components/alexa_media/init.py, line 360: await login.login(cookies=await login.load_cookie()) (offender: /usr/local/lib/python3.12/site-packages/aiohttp/cookiejar.py, line 118: with file_path.open(mode=“rb”) as f:), please create a bug report at https://github.com/alandtse/alexa_media_player/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 189, 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/config_entries.py”, line 752, in async_setup_locked await self.async_setup(hass, integration=integration) File “/usr/src/homeassistant/homeassistant/config_entries.py”, line 604, in async_setup result = await component.async_setup_entry(hass, self) File “/config/custom_components/alexa_media/init.py”, line 360, in async_setup_entry await login.login(cookies=await login.load_cookie())
2024-09-04 19:37:08.988 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to open with args (PosixPath(‘/config/.storage/alexa_media.XXX@XX.pickle’),) inside the event loop by custom integration ‘alexa_media’ at custom_components/alexa_media/init.py, line 360: await login.login(cookies=await login.load_cookie()) (offender: /usr/local/lib/python3.12/site-packages/aiohttp/cookiejar.py, line 113: with file_path.open(mode=“wb”) as f:), please create a bug report at https://github.com/alandtse/alexa_media_player/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 189, 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/config_entries.py”, line 752, in async_setup_locked await self.async_setup(hass, integration=integration) File “/usr/src/homeassistant/homeassistant/config_entries.py”, line 604, in async_setup result = await component.async_setup_entry(hass, self) File “/config/custom_components/alexa_media/init.py”, line 360, in async_setup_entry await login.login(cookies=await login.load_cookie())
2024-09-04 19:37:09.071 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to load_verify_locations with args (<ssl.SSLContext object at 0x7f155d069e50>,) inside the event loop by custom integration ‘alexa_media’ at custom_components/alexa_media/init.py, line 875: http2 = HTTP2EchoClient( (offender: /usr/local/lib/python3.12/site-packages/httpx/_config.py, line 147: context.load_verify_locations(cafile=cafile)), please create a bug report at https://github.com/alandtse/alexa_media_player/issues For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#load_verify_locations 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 189, 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/config_entries.py”, line 752, in async_setup_locked await self.async_setup(hass, integration=integration) File “/usr/src/homeassistant/homeassistant/config_entries.py”, line 604, in async_setup result = await component.async_setup_entry(hass, self) File “/config/custom_components/alexa_media/init.py”, line 362, in async_setup_entry await setup_alexa(hass, config_entry, login) File “/config/custom_components/alexa_media/init.py”, line 1265, in setup_alexa await http2_connect() File “/config/custom_components/alexa_media/init.py”, line 875, in http2_connect http2 = HTTP2EchoClient(
Additional context
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 19
- Comments: 35 (2 by maintainers)
@stefano This issue is not a bug! It is a warning only! This part of the code has always been this way and it’s only now that HA is checking for these types of blocking calls in the event loop that we (and many other integrations as well, including HA Core native integrations!) are being notified that our code is hindering performance. The loop is only blocked for the duration of the call and therefore only affects the overall performance of HA.
Is there a “plan”? No, there’s no one at the ship’s helm! There’s only users like you, me, @RogerSelwyn, etc.
I repeat…“Detected blocking call to load_verify_locations” is a WARNING ONLY and has NOTHING WHATSOEVER to do with any issues you might be having! DO NOT POST YOUR ISSUES HERE!
I take this opportunity to thank you for all the help you have given us, selflessly, and for that time which is surely a lot to make the component work, I thank you from the bottom of my heart.
Just had a go at solving the one at line 343. As you say seems easier said than done since it seems like it goes from sync call to AlexaLogin class which then initiates an async call. I’m not knowledgeable enough, I’ll do some digging, because I’ve used hass.async_add_executor_job I think it has moved it outside the loop, and then when it trues to go async inside AlexaLogin it can’t find the loop to start a session from.
Edit: I think AlexaLogin needs to be modified to allow a session to be passed in, which looking at the code would be a fairly easy change. Probably needs a discussion with @alandtse.
Thanks but I already have all the logs. And there are multiple blocking calls beyond just the certs…
I’ll try to take a look when I get a chance. It’ll make a change from adding testing to an integration I created.
I am encountering this error during initial configuration of the integration and therefore it cannot be added. My information is the same as above, except for the Amazon domain, which for me is amazon.com
The problem seems resolved with AMP v4.13.5
There are pending merge requests in alexapy to address the “WARNING: Detected blocking call” messages: !394 - fix: run aiohttp.cookiejar load/save functions in executor loop (alexalogin.py) !395 - fix: define ssl.create_default_context as a top level import (alexalogin.py) !396 - fix: define ssl.create_default_context as a top level import (alexahttp2.py)
+1,
Detected blocking call to load_verify_locations with args (<ssl.SSLContext object at 0x7f57e11f50>,) inside the event loop by custom integration ‘alexa_media’ at custom_components/alexa_media/init.py, line 922: http2 = HTTP2EchoClient( (offender: /usr/local/lib/python3.12/site-packages/httpx/_config.py, line 149: context.load_verify_locations(cafile=cafile)), please create a bug report at https://github.com/alandtse/alexa_media_player/issues
So now we rely in AI to fix the code?
Analysis by ChatGPT:
Here is a summary of the issues that are outside our scope and why we cannot fix them directly:
1. Blocking SSL operations (
load_verify_locations):load_verify_locationsis part of Python’s built-inssllibrary, which handles SSL context verification.ssllibrary itself.2.
AlexaLoginobject lacksssl_context:AlexaLoginobject does not expose or provide access to anssl_contextattribute, which prevents us from manually controlling SSL verification processes within this object.ssl_contextattribute in theAlexaLoginclass is part of its internal design. Since this is a third-party library (alexapy), we do not have control over its internal structure. To resolve this, we’d need either the library maintainers to modify the class or to extend the library ourselves, which is outside the scope of this discussion.3. SSL operations deeply integrated into third-party libraries:
alexapy(used byalexa_media), which are responsible for making network requests to Amazon’s services.In summary, these issues involve built-in Python behaviors and third-party library structures that we cannot modify directly. To resolve them, contributions or fixes from the maintainers of those libraries would be necessary.
Got the same issue. Has been doing this for a while now.
The integration has become unusable and useless… the entities are shown as offline and not working anymore. This bug + the bug related to the reauth issue are making this custom component not working anymore.
Any plan to fix it?
I’ve tried every which way from Sunday that I can think of to implement that here:
alexa_meda/__init__.pyThis is the function in
alexapy/alexalogin.py:I think this is one of the blocking calls within
load_cookie:You are likely to need to wrap the call to the offending function with ‘await hass.async_add_executor_job’, which obviously nee ds to be done from an async function. This will push it outside the executor thread.
If the function call was ‘blockingfunction(param1, param2)’ this would get changed to 'await hass.async_add_executor_job(blockingfunction, param1, param2).
You will need access to hass somewhere, but it’s usually hanging around somewhere.
!!! IT’S JUST A WARNING !!! The blocking call has always been there. It’s just that HA Core is becoming smarter about checking for and reporting on these async blocking calls in its ongoing attempts to streamline and keep everything internal running smoothly and quickly.
Possibly, but I do not know how, or where (alexa_media or alexpy)
It’s all outlined in Blocking operations with asyncio but it’s all pseudo code and trying to figure out exactly what should be changed and how is beyond my current skill level.
Experiencing the same issue, it started occurring since the latest update to the integration - before this point the error was not experienced.
How does this affect Alexa Media Player?How does this affect Alexa Media Player?