Fix blocking SSL cert load on event loop (#578)#580
Conversation
Pass HA's pre-warmed cached ssl.SSLContext into httpx.AsyncClient instead of letting httpx build one synchronously. The v9.0.0 cookie-isolation refactor replaced get_async_client() with direct AsyncClient construction, which reintroduced load_verify_locations() on the event loop. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughHttpSession now constructs its httpx.AsyncClient with pre-warmed SSL contexts from Home Assistant helpers instead of passing a boolean verify_ssl flag, eliminating a blocking call to load_verify_locations during event loop initialization. A regression test verifies the blocking call no longer occurs. ChangesSSL Context Pre-warming
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
load_verify_locationsat scraper setup.ssl.SSLContext(fromhomeassistant.util.ssl) intohttpx.AsyncClient(verify=...)instead of letting httpx build a fresh context synchronously, which read certifi's CA bundle from disk on the event loop.httpx.AsyncClientperHttpSession). Going back toget_async_clientwould have re-broken that.Why this is a regression in v9.0.0
v8.0.5 used
homeassistant.helpers.httpx_client.get_async_client(hass, verify_ssl), which returns HA's shared client built on the cached SSL context — no blocking call ever fired. v9.0.0 commit8ee795areplaced the shared helper with directhttpx.AsyncClient(verify=bool, ...)to give each scraper its own cookie jar, which reintroduced the cert load on the event loop.homeassistant.util.sslpre-warms verifying and no-verify SSL contexts at module-load time precisely so integrations can grab a ready-to-use context without blocking I/O. We use those directly; we don't go throughcreate_async_httpx_clientbecause it wrapsaclosewithwarn_use, which would warn on everyHttpSession.async_close().Test plan
pytest tests/)test_init_does_not_load_verify_locations(parametrized oververify_ssl=True/False) assertsssl.SSLContext.load_verify_locationsis not invoked duringHttpSession.__init__Detected blocking call to load_verify_locationswarning no longer fires at startup or duringmultiscrape.scrapeservice calls🤖 Generated with Claude Code
Summary by CodeRabbit
Technical Improvements
Tests