Skip to content

Fix blocking httpx calls inside the event loop#68

Open
emanuelstrom wants to merge 1 commit into
linsvensson:masterfrom
emanuelstrom:fix/blocking-ssl-calls
Open

Fix blocking httpx calls inside the event loop#68
emanuelstrom wants to merge 1 commit into
linsvensson:masterfrom
emanuelstrom:fix/blocking-ssl-calls

Conversation

@emanuelstrom

Copy link
Copy Markdown

Fixes #59
Fixes #66

What

Three remaining call sites called sync httpx.get() / httpx.post() from within async contexts:

  • __init__.py: async_setup_entryapi.check_auth() and api.get_facility_id()
  • config_flow.py: Greenelyhub.authenticate / .get_facility_id (declared async but bodies were sync)
  • services.py: async_fetch_facilitiesapi.check_auth() and api.get_facility_ids()

Each sync HTTPS request triggers ssl.SSLContext.load_verify_locations on first use, which Home Assistant now warns about:

Detected blocking call to load_verify_locations inside the event loop

How

Wrapped each call in hass.async_add_executor_job(...) so the blocking work runs on a thread. Greenelyhub now receives hass to use the executor.

The sync update() polling path in sensor.py is unaffected — those methods are already executed on an executor thread by Home Assistant's polling system, so they were never the source of the warnings.

Testing

  • Manually verified config flow still completes without warnings
  • Sensors keep updating

The integration calls synchronous httpx HTTPS requests from within
async contexts (async_setup_entry, the config flow's authenticate /
get_facility_id, and the fetch_facilities service). Each sync HTTPS
call triggers ssl.SSLContext.load_verify_locations on first use, which
Home Assistant flags with "Detected blocking call to load_verify_locations
inside the event loop" warnings.

This wraps the three remaining sync-in-async call sites in
hass.async_add_executor_job so the work runs in a thread instead of
blocking the loop. The sync update() polling path in sensor.py is
unaffected because those methods are already executed on an executor
thread by Home Assistant.

Fixes linsvensson#59
Fixes linsvensson#66
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

Successfully merging this pull request may close these issues.

Blocking call to load_verify_locations in event loop "Detected blocking call to load_verify_locations"

1 participant