Blocking call to httpx.create_ssl_context() in async_setup_entry freezes entire Home Assistant instance
- Lenguaje dominante
- Python
- Estrellas
- 780
- Forks
- 127
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
### Describe the bug
`create_tesla_ssl_context()` (custom_components/tesla_custom/util.py, line 26)
calls `httpx.create_ssl_context()` synchronously from `async_setup_entry`
(__init__.py, line 145). Internally this calls
`ssl.SSLContext.load_verify_locations()`, which is a blocking disk I/O call.
Since this runs directly inside the async event loop (not wrapped in
`hass.async_add_executor_job()` or `asyncio.to_thread()`), it blocks HA's
entire single-threaded event loop for the duration of the call - not just
the Tesla integration.
In my case this coincided with the whole Home Assistant instance becoming
unresponsive (UI not loading / extremely slow) right after startup, requiring
a full reboot. The issue recurred on the next restart, since
`async_setup_entry` runs again on every boot.
### Log
```
Logger: homeassistant.util.loop
Source: util/loop.py:135
First occurred: 16:31:48 (1 occurrence)
Last logged: 16:31:48
Detected blocking call to load_verify_locations with args
(,
'/usr/local/lib/python3.14/site-packages/certifi/cacert.pem', None, None)
inside the event loop by custom integration 'tesla_custom' at
custom_components/tesla_custom/util.py, line 26:
ctx = httpx.create_ssl_context()
(offender: /usr/local/lib/python3.14/ssl.py, line 717:
context.load_verify_locations(cafile, capath, cadata))
Traceback (most recent call last):
File "/config/custom_components/tesla_custom/__init__.py", line 145, in async_setup_entry
tesla_ssl_context = create_tesla_ssl_context()
File "/config/custom_components/tesla_custom/util.py", line 26, in create_tesla_ssl_context
ctx = httpx.create_ssl_context()
```
### Environment
- Integration version: 3.27.0
- teslajsonpy: 3.13.2
- Home Assistant Core: will confirm in a follow-up comment
- Python: 3.14
### Suggested fix
Wrap the SSL context creation in an executor, e.g.:
tesla_ssl_context = await hass.async_add_executor_job(create_tesla_ssl_context)
### Additional context
See Home Assistant's own documentation on this:
https://developers.home-assistant.io/docs/asyncio_blocking_operations/#load_verify_locations
Guía de contribución
Línea de trabajo
Start in custom_components/tesla_custom/util.py at create_tesla_ssl_context() and custom_components/tesla_custom/__init__.py at async_setup_entry(), then review Home Assistant's blocking-operation guidance for load_verify_locations. Confirm the SSL context setup no longer blocks the event loop and that startup no longer reports the detected blocking-call warning.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- backend
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Tranquilo
- Claridad
- Bien especificado
- Aptitud para principiantes
- 78/100