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

WARNING: Detected blocking call to load_verify_locations with args (<ssl.SSLContext object at 0x7f155d069e50>,) inside the event loop by custom integration 'alexa_media #2504

Closed
StefanoGiu opened this issue Sep 4, 2024 · 35 comments

Comments

@StefanoGiu
Copy link

StefanoGiu commented Sep 4, 2024

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.py or HA startup log): 4.12.11
  • alexapy version (from pip show alexapy in 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 "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "/usr/src/homeassistant/homeassistant/main.py", line 223, in
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
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/[email protected]'),) 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 "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "/usr/src/homeassistant/homeassistant/main.py", line 223, in
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/[email protected]'),) 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 "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "/usr/src/homeassistant/homeassistant/main.py", line 223, in
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 "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "/usr/src/homeassistant/homeassistant/main.py", line 223, in
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

@javiges
Copy link

javiges commented Sep 4, 2024

So notifications fail again?

@millenniumy2k
Copy link

Same problem

@javiges
Copy link

javiges commented Sep 4, 2024

Describe the bug

Errors in the log

To Reproduce

Nothing, check the log

Expected behavior

No error should be there

System details

  • Home Assistant version: 2024.9.0
  • alexa_media version (from const.py or HA startup log): 4.12.11
  • alexapy version (from pip show alexapy in 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 "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/main.py", line 223, in 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 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/[email protected]'),) 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 "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/main.py", line 223, in 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/[email protected]'),) 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 "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/main.py", line 223, in 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 "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/usr/src/homeassistant/homeassistant/main.py", line 223, in 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

How does this affect Alexa Media Player?How does this affect Alexa Media Player?

@z3gator
Copy link

z3gator commented Sep 4, 2024

How does this affect Alexa Media Player?How does this affect Alexa Media Player?

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

@javiges
Copy link

javiges commented Sep 5, 2024

is it possible to fix it?

@jasonv234
Copy link

Experiencing the same issue, it started occurring since the latest update to the integration - before this point the error was not experienced.

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Sep 6, 2024

!!! 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.

is it possible to fix it?

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.

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Sep 6, 2024

FWIW, the Core integration Netdata has triggered the same WARNING...
Netdata: warnings in 2024.9 - "Detected blocking call" #125260

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Sep 6, 2024

The Core integration BMW Connected Drive also had the same warning.
BMW Connected Drive - Detected blocking call warning during HASS startup with 2024.9.0b2 #124942

Logger: homeassistant.util.loop
Quelle: util/loop.py:136
Erstmals aufgetreten: 20:25:29 (1 Vorkommnisse)
Zuletzt protokolliert: 20:25:29

Detected blocking call to load_verify_locations with args (<ssl.SSLContext object at 0x7fa40f15fb50>,) inside the event loop by integration 'bmw_connected_drive' at homeassistant/components/bmw_connected_drive/coordinator.py, line 61: await self.account.get_vehicles() (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/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+bmw_connected_drive%22 
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 "/usr/src/homeassistant/homeassistant/components/bmw_connected_drive/__init__.py", line 142, in async_setup_entry await coordinator.async_config_entry_first_refresh()
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 281, in async_config_entry_first_refresh await self._async_refresh( )
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 354, in _async_refresh self.data = await self._async_update_data() 
File "/usr/src/homeassistant/homeassistant/components/bmw_connected_drive/coordinator.py", line 61, in _async_update_data await self.account.get_vehicles()

Changes were required in both the HA Core integration BMW Connected Drive and it's required library bimmer-conneced 0.16.3 which would be akin to alexa_media & alexapy.
See:
Fix BMW client blocking on load_default_certs #125015
and
Allow passing external SSL context #655

I think I see how changes in homeassistant/components/bmw_connected_drive/coordinator.py could be applied to alexa_media/__init__.py.

As for alexapy/alexalogin.py, I don't know yet how it compares to bimmer-connected/account.py...

@RogerSelwyn
Copy link

!!! 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.

is it possible to fix it?

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.

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.

@msavazzi
Copy link

msavazzi commented Sep 7, 2024

same problem for me.
If it helps I've logged (and closed) a bug with all the info an the log: #2512

@danielbrunt57
Copy link
Collaborator

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.

I've tried every which way from Sunday that I can think of to implement that here:
alexa_meda/__init__.py

    login: AlexaLogin = hass.data[DATA_ALEXAMEDIA]["accounts"][email].get(
        "login_obj",
        AlexaLogin(
            url=url,
            email=email,
            password=password,
            outputpath=hass.config.path,
            debug=account.get(CONF_DEBUG),
            otp_secret=account.get(CONF_OTPSECRET, ""),
            oauth=account.get(CONF_OAUTH, {}),
            uuid=uuid,
            oauth_login=True,
        ),
    )
    hass.data[DATA_ALEXAMEDIA]["accounts"][email]["login_obj"] = login
    hass.data[DATA_ALEXAMEDIA]["accounts"][email]["last_push_activity"] = 0
    if not hass.data[DATA_ALEXAMEDIA]["accounts"][email]["second_account_index"]:
        hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, close_alexa_media)
        hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, complete_startup)
    hass.bus.async_listen("alexa_media_relogin_required", relogin)
    hass.bus.async_listen("alexa_media_relogin_success", login_success)
    try:
        await login.login(cookies=await login.load_cookie())    ## Original ## 
        
        #EXAMPLE result = await hass.async_add_executor_job(blocking_code, "something")
        #EXAMPLE result = await hass.async_add_executor_job(partial(blocking_code_with_kwargs, kwarg=True))

        #await login.login(cookies=await hass.async_add_executor_job(login.load_cookie))
        #loaded_cookie = await hass.async_add_executor_job(login.load_cookie)
        #await hass.async_add_executor_job(partial(login.login, cookies=loaded_cookie))
        #await login.login(cookies=loaded_cookie)
        #await hass.async_add_executor_job(login.login, "cookies=await login.load_cookie()")
        #await hass.async_add_executor_job(partial(login.login, cookies=login.load_cookie))
        #await hass.async_add_executor_job(partial(login.login, cookies=await login.load_cookie()))
        #await hass.async_add_executor_job(partial(blocking_code_with_kwargs, kwarg=True))
        #cookies = await hass.async_add_executor_job(login.load_cookie)
        #result = await hass.async_add_executor_job(login.login,cookies)
        
        if await test_login_status(hass, config_entry, login):
            await setup_alexa(hass, config_entry, login)
            return True
        return False

This is the function in alexapy/alexalogin.py:

    async def load_cookie(self, cookies_txt: str = "") -> Optional[dict[str, str]]:
        # pylint: disable=import-outside-toplevel
        """Load cookie from disk."""

I think this is one of the blocking calls within load_cookie:

                try:
                    async with aiofiles.open(cookiefile, "rb") as myfile:
                        cookies = pickle.loads(await myfile.read())
                        if self._debug:
                            _LOGGER.debug(
                                "Pickled cookie loaded: %s %s", type(cookies), cookies
                            )

@RogerSelwyn
Copy link

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.

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Sep 7, 2024

same problem for me. If it helps I've logged (and closed) a bug with all the info an the log: #2512

Thanks but I already have all the logs.
And there are multiple blocking calls beyond just the certs...

@RogerSelwyn
Copy link

Looking at the original error, lines 340, 360 and 875 need wrapping. But at least one has a keyword argument, so it may need a partial well. At line 360 there is an await embedded as a parameter (seems weird to me). I’d probably break it apart, create the cookie on one line then pass it as a parameter on the next. It would make it easier to identify the issue.

On my phone at the moment, but may look on a big screen in a short while.

@RogerSelwyn
Copy link

RogerSelwyn commented Sep 7, 2024

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.

@StefanoGiu
Copy link
Author

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?

@danielbrunt57
Copy link
Collaborator

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.

@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.

Any plan to fix it?

Is there a "plan"? No, there's no one at the ship's helm! There's only users like you, me, @RogerSelwyn, etc.

@danielbrunt57 danielbrunt57 changed the title Detected blocking call to load_verify_locations with args (<ssl.SSLContext object at 0x7f155d069e50>,) inside the event loop by custom integration 'alexa_media WARNING: Detected blocking call to load_verify_locations with args (<ssl.SSLContext object at 0x7f155d069e50>,) inside the event loop by custom integration 'alexa_media Sep 9, 2024
@kmil4
Copy link

kmil4 commented Sep 10, 2024

Is this why I suddenly have busted HA devices inside of Alexa? All the devices I expose through home assistant to Alexa are showing as unreachable suddenly. And I get the same warning in logs. Can't use my voice commands hardly at all

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Sep 10, 2024

Is this why I suddenly have busted HA devices inside of Alexa? All the devices I expose through home assistant to Alexa are showing as unreachable suddenly. And I get the same warning in logs. Can't use my voice commands hardly at all

@kmil4,
No.

  1. Devices exposed from HA to Alexa have nothing to do with this integration. You need to look at your Amazon Alexa Integration, which is done either through Nabu Casa cloud: or via manual skill creation (Amazon Alexa Smart Home Skill)
  2. This issue is only for "warning" messages about AMP and they are just that, a warning!

@javiges
Copy link

javiges commented Sep 10, 2024

¿Es por esto que de repente tengo dispositivos HA dañados dentro de Alexa? Todos los dispositivos que expongo a Alexa a través del asistente de hogar se muestran como inaccesibles de repente. Y recibo la misma advertencia en los registros. Casi no puedo usar mis comandos de voz

No.

  1. Los dispositivos expuestos desde HA a Alexa no tienen nada que ver con esta integración. Debes consultar tu integración con Amazon Alexa , que se realiza a través de Nabu Casa cloud:o mediante la creación manual de habilidades ( Habilidad de Amazon Alexa Smart Home )
  2. Este problema es solo para mensajes de "advertencia" sobre AMP y son solo eso, ¡una advertencia !

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.

@beasthouse-au
Copy link

Got the same issue. Has been doing this for a while now.

@jleinenbach
Copy link
Contributor

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):

  • Issue: The function load_verify_locations is part of Python's built-in ssl library, which handles SSL context verification.
  • Why we can't fix it: This function is inherently blocking and resides in the standard Python library, which we cannot modify directly. The problem is that SSL verification is designed to block while verifying certificates, and altering this behavior would require changes at the core Python level or within the ssl library itself.

2. AlexaLogin object lacks ssl_context:

  • Issue: The AlexaLogin object does not expose or provide access to an ssl_context attribute, which prevents us from manually controlling SSL verification processes within this object.
  • Why we can't fix it: The lack of an ssl_context attribute in the AlexaLogin class 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:

  • Issue: The SSL verification that causes blocking is handled internally by third-party libraries, such as alexapy (used by alexa_media), which are responsible for making network requests to Amazon's services.
  • Why we can't fix it: The SSL verification is part of how these libraries handle secure communication, and altering this would require modifying the internal behavior of the third-party libraries. Since we are users of these libraries and not their maintainers, making such deep changes would be impractical and would likely require submitting requests or pull requests to the library maintainers.

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.

@StefanoGiu
Copy link
Author

So now we rely in AI to fix the code?

@jleinenbach
Copy link
Contributor

So now we rely in AI to fix the code?

So you can do better? Go on!

@StefanoGiu
Copy link
Author

I don't know how the code works, if you can teach me the code, I will be glad to fix it.

I always take care of bugs of my own code...

@lindap1978
Copy link

Hi Daniel,
How is the progress here? I still can't connect 6 echo devices? Is there any plan when it will work?

Best Regards
Petr

@Palmdale95
Copy link

I got the same error message by the custom homematic ip integration by the way. So it looks like a generall issue. (running latest stable version on proxmox)

@PrathikGopal
Copy link

+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

@danielbrunt57
Copy link
Collaborator

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!

Repository owner deleted a comment from Jendoff Oct 7, 2024
Repository owner deleted a comment from beasthouse-au Oct 7, 2024
Repository owner deleted a comment from santu-4684 Oct 7, 2024
Repository owner deleted a comment from StefanoGiu Oct 7, 2024
@StefanoGiu
Copy link
Author

So why this component became buggy and it's not working anymore. It requires continuous reauthentication... what's the error related to this and when will it be fixed?

@danielbrunt57
Copy link
Collaborator

So why this component became buggy and it's not working anymore.

It started back in June with web browsers new partitioned cookies structure.
It got worse with with HA 2024.8 and the new aiohttp library and it just keeps getting one thing after another thrown at it.
Like changes in Amazon throttling policies and also Amazon redesigned the Alexa login windows from a two page email+password then TOTP login to three pages: email, then password, then TOTP.

It requires continuous reauthentication.

My installation is fine - no re-auth required.

what's the error related to this

You have to analyze your logs.

when will it be fixed?

Your guess is as good as mine, maybe never.
There are only a handful of more knowledgeable users like myself trying to patch it as best we know how...

@santu-4684
Copy link

I am able to login after supervisor update followed by Create Account option even though account exists able to restore the integration. Thanks all for the feedback and suggestion.

@danielbrunt57
Copy link
Collaborator

danielbrunt57 commented Oct 19, 2024

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)

@micium
Copy link

micium commented Oct 20, 2024

The problem seems resolved with AMP v4.13.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests