nordicopen / easee_hass

Custom component for Easee EV charger integration with Home Assistant
216 stars 37 forks source link

WARNING (MainThread) [homeassistant.util.loop] #466

Open enoch85 opened 2 months ago

enoch85 commented 2 months ago

The problem

Please see here: https://github.com/home-assistant/core/issues/125949

Version of Easee integration having the issue?

0.9.59

Version of Home Assistant Core having the issue?

2024.09.1

Anything in the logs that might be useful for us?

2024-09-13 20:26:33.579 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to load_default_certs with args (<ssl.SSLContext object at 0x7f061e2bda50>, <Purpose.SERVER_AUTH: _ASN1Object(nid=129, shortname='serverAuth', longname='TLS Web Server Authentication', oid='1.3.6.1.5.5.7.3.1')>) in /usr/local/lib/python3.12/ssl.py, line 713: context.load_default_certs(purpose) inside the event loop; This is causing stability issues. Please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#load_default_certs
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/local/lib/python3.12/site-packages/pyeasee/easee.py", line 301, in _sr_connect_loop
await self.sr_connection.run()
File "/usr/local/lib/python3.12/site-packages/pysignalr/client.py", line 92, in run
await self._transport.run()
File "/usr/local/lib/python3.12/site-packages/pysignalr/transport/websocket.py", line 77, in run
await self._loop()
File "/usr/local/lib/python3.12/site-packages/pysignalr/transport/websocket.py", line 102, in _loop
async for conn in connection_loop:
File "/usr/local/lib/python3.12/site-packages/pysignalr/init.py", line 26, in aiter
async with self as protocol:
File "/usr/local/lib/python3.12/site-packages/websockets/legacy/client.py", line 629, in aenter
return await self
File "/usr/local/lib/python3.12/site-packages/websockets/legacy/client.py", line 647, in await_impl_timeout
return await self.await_impl()
File "/usr/local/lib/python3.12/site-packages/websockets/legacy/client.py", line 651, in await_impl
_transport, _protocol = await self._create_connection()
File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1149, in create_connection
transport, protocol = await self._create_connection_transport(
File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1173, in _create_connection_transport
transport = self._make_ssl_transport(
File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 83, in _make_ssl_transport
ssl_protocol = sslproto.SSLProtocol(
File "/usr/local/lib/python3.12/asyncio/sslproto.py", line 295, in init
sslcontext = _create_transport_context(
File "/usr/local/lib/python3.12/asyncio/sslproto.py", line 55, in _create_transport_context
sslcontext = ssl.create_default_context()
File "/usr/local/lib/python3.12/ssl.py", line 713, in create_default_context
context.load_default_certs(purpose)

Additional information

No response

olalid commented 2 months ago

Hmm, I can not reproduce this in my installation. Could there be some issue with your libs possibly, since the cause of the exception is inside ssl.py? What version of pysignalr, websockets and asyncio do you have?

enoch85 commented 2 months ago

Hmm, I can not reproduce this in my installation. Could there be some issue with your libs possibly, since the cause of the exception is inside ssl.py? What version of pysignalr, websockets and asyncio do you have?

Sorry, how do I get version info? I'm on HAOS.

olalid commented 2 months ago

Never mind, I can see it too now.

ridderr commented 1 month ago

Same here with me. Not sure if this is now beeing solved?

`Logger: homeassistant.util.loop Bron: util/loop.py:77 Eerst voorgekomen: 13:35:15 (1 gebeurtenissen) Laatst gelogd: 13:35:15

Detected blocking call to load_default_certs with args (<ssl.SSLContext object at 0x7f63f20dd0>, <Purpose.SERVER_AUTH: _ASN1Object(nid=129, shortname='serverAuth', longname='TLS Web Server Authentication', oid='1.3.6.1.5.5.7.3.1')>) in /usr/local/lib/python3.12/ssl.py, line 713: context.load_default_certs(purpose) inside the event loop; This is causing stability issues. Please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#load_default_certs 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/local/lib/python3.12/site-packages/pyeasee/easee.py", line 312, in _sr_connect_loop await self.sr_connection.run() File "/usr/local/lib/python3.12/site-packages/pysignalr/client.py", line 92, in run await self._transport.run() File "/usr/local/lib/python3.12/site-packages/pysignalr/transport/websocket.py", line 77, in run await self._loop() File "/usr/local/lib/python3.12/site-packages/pysignalr/transport/websocket.py", line 102, in _loop async for conn in connection_loop: File "/usr/local/lib/python3.12/site-packages/pysignalr/init.py", line 26, in aiter async with self as protocol: File "/usr/local/lib/python3.12/site-packages/websockets/legacy/client.py", line 629, in aenter return await self File "/usr/local/lib/python3.12/site-packages/websockets/legacy/client.py", line 647, in await_impl_timeout return await self.await_impl() File "/usr/local/lib/python3.12/site-packages/websockets/legacy/client.py", line 651, in await_impl _transport, _protocol = await self._create_connection() File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1149, in create_connection transport, protocol = await self._create_connection_transport( File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1173, in _create_connection_transport transport = self._make_ssl_transport( File "/usr/local/lib/python3.12/asyncio/selector_events.py", line 83, in _make_ssl_transport ssl_protocol = sslproto.SSLProtocol( File "/usr/local/lib/python3.12/asyncio/sslproto.py", line 295, in init sslcontext = _create_transport_context( File "/usr/local/lib/python3.12/asyncio/sslproto.py", line 55, in _create_transport_context sslcontext = ssl.create_default_context() File "/usr/local/lib/python3.12/ssl.py", line 713, in create_default_context context.load_default_certs(purpose)`

olalid commented 1 month ago

Not sure how to solve it yet. It does not really stop anything from working correctly, it is just a warning that HA puts in the log when it detects blocking I/O in an integration. In our case it happens in an external library which is out of our control how it is implemented. This happens only once during startup so it is not really a big deal for the performance of HA in general. But still, would be nice to get rid of it.

olalid commented 2 weeks ago

Well, this is mostly a note to myself, but anyway... The solution to this seems to be to provide an SSL context to the websockets lib instead of relying on it self to create such a context (which it will do with blocking I/O). Problem is that all calls to the websockets lib is handled completely by pysignalr lib, so it will require a change of pysignalr lib to get rid of this problem. It will require a change to pyeasee too since the SSL context must come from HA, but that is of course less problematic since that is our code.

olalid commented 1 week ago

PR created for pysignalr, lets see if that will be accepted. https://github.com/baking-bad/pysignalr/pull/19