fix: replace module-level SSLContext with verify=True to prevent event loop blocking#48
Conversation
…t loop blocking The default session_factory used httpx.AsyncClient(verify=ssl_context) where ssl_context was a module-level create_default_context() object. When this factory is invoked inside an async event loop (e.g., from reset_data() during Home Assistant config flow), httpx internally calls ssl.SSLContext.load_verify_locations(), which is a blocking I/O operation. On Python 3.13+ and Home Assistant 2024.10+, this triggers: 'Detected blocking call to load_verify_locations inside the event loop' Using verify=True instead lets httpx handle SSL verification through its own default certifi CA bundle, achieving the same security level without the blocking call. Fixes: alandtse/alexa_media_player#3380 Fixes: alandtse/alexa_media_player#2504 Fixes: alandtse/alexa_media_player#2503 Fixes: alandtse/alexa_media_player#2625 Fixes: alandtse/alexa_media_player#2519
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe module-level SSL context preconfiguration has been removed from the auth capture proxy. The HTTP client session factory now relies on the default SSL verification behavior ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
|
@diegolameira Please address the pull request test failure! |
Problem
The default
session_factoryinAuthCaptureProxy.__init__uses:When this factory is called inside an async event loop (e.g., from
reset_data()during a Home Assistant config flow),httpxinternally callsssl.SSLContext.load_verify_locations(), which is a blocking I/O operation.On Python 3.13+ and Home Assistant 2024.10+, this triggers:
In some configurations (especially with HA 2026.4+ / Python 3.14), this blocking call can cause HA Core to crash with exit code 100 and enter a restart loop, making the entire instance unreachable.
Fix
Replace
verify=ssl_contextwithverify=True. This lets httpx handle SSL verification through its own default certifi CA bundle — same security level, no blocking call.The module-level
create_default_context()and its import are also removed since they're no longer needed (theSSLContextimport is retained forstart_proxy()).Related Issues
Testing
exit code 100,load_verify_locationsblocking warningsSummary by CodeRabbit