franc6 / ics_calendar

Provides an ICS (icalendar) platform for the Home Assistant calendar
Apache License 2.0
146 stars 22 forks source link

Detected blocking call to load_default_certs #166

Open definitio opened 1 week ago

definitio commented 1 week ago
2024-09-15 15:38:15.269 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to load_default_certs with args (<ssl.SSLContext object at 0x77ac2ebf58d0>, <Purpose.SERVER_AUTH: _ASN1Object(nid=129, shortname='serverAuth', longname='TLS Web Server Authentication', oid='1.3.6.1.5.5.7.3.1')>) inside the event loop by custom integration 'ics_calendar' at custom_components/ics_calendar/calendardata.py, line 134: self._opener = build_opener( (offender: /usr/local/lib/python3.12/ssl.py, line 713: context.load_default_certs(purpose)), please create a bug report at https://github.com/franc6/ics_calendar/issues
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#load_default_certs
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/usr/src/homeassistant/homeassistant/__main__.py", line 223, in <module>
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/src/homeassistant/homeassistant/config_entries.py", line 2214, in _async_forward_entry_setup
await entry.async_setup(self.hass, integration=integration)
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 604, in async_setup
result = await component.async_setup_entry(hass, self)
File "/usr/src/homeassistant/homeassistant/components/calendar/__init__.py", line 319, in async_setup_entry
return await component.async_setup_entry(entry)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 194, in async_setup_entry
return await self._platforms[key].async_setup_entry(config_entry)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 328, in async_setup_entry
return await self._async_setup_platform(async_create_setup_awaitable)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 358, in _async_setup_platform
awaitable = create_eager_task(awaitable, loop=hass.loop)
File "/usr/src/homeassistant/homeassistant/util/async_.py", line 45, in create_eager_task
return Task(coro, loop=loop, name=name, eager_start=True)
File "/config/custom_components/ics_calendar/calendar.py", line 67, in async_setup_entry
entity = ICSCalendarEntity(
File "/config/custom_components/ics_calendar/calendar.py", line 145, in __init__
self.data = ICSCalendarData(device_data)
File "/config/custom_components/ics_calendar/calendar.py", line 261, in __init__
self._calendar_data.set_headers(
File "/config/custom_components/ics_calendar/calendardata.py", line 134, in set_headers
self._opener = build_opener(
definitio commented 1 week ago

It's still there with v5.0.3:

2024-09-17 23:07:16.486 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to load_default_certs with args (<ssl.SSLContext object at 0x79a9fff21350>, <Purpose.SERVER_AUTH: _ASN1Object(nid=129, shortname='serverAuth', longname='TLS Web Server Authentication', oid='1.3.6.1.5.5.7.3.1')>) inside the event loop by custom integration 'ics_calendar' at custom_components/ics_calendar/calendardata.py, line 134: self._opener = build_opener( (offender: /usr/local/lib/python3.12/ssl.py, line 713: context.load_default_certs(purpose)), please create a bug report at https://github.com/franc6/ics_calendar/issues
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#load_default_certs
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/usr/src/homeassistant/homeassistant/__main__.py", line 223, in <module>
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/src/homeassistant/homeassistant/config_entries.py", line 2214, in _async_forward_entry_setup
await entry.async_setup(self.hass, integration=integration)
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 604, in async_setup
result = await component.async_setup_entry(hass, self)
File "/usr/src/homeassistant/homeassistant/components/calendar/__init__.py", line 319, in async_setup_entry
return await component.async_setup_entry(entry)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 194, in async_setup_entry
return await self._platforms[key].async_setup_entry(config_entry)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 328, in async_setup_entry
return await self._async_setup_platform(async_create_setup_awaitable)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 358, in _async_setup_platform
awaitable = create_eager_task(awaitable, loop=hass.loop)
File "/usr/src/homeassistant/homeassistant/util/async_.py", line 45, in create_eager_task
return Task(coro, loop=loop, name=name, eager_start=True)
File "/config/custom_components/ics_calendar/calendar.py", line 65, in async_setup_entry
hass.async_create_task(
File "/usr/src/homeassistant/homeassistant/core.py", line 807, in async_create_task
return self.async_create_task_internal(target, name, eager_start)
File "/usr/src/homeassistant/homeassistant/core.py", line 829, in async_create_task_internal
task = create_eager_task(target, name=name, loop=self.loop)
File "/usr/src/homeassistant/homeassistant/util/async_.py", line 45, in create_eager_task
return Task(coro, loop=loop, name=name, eager_start=True)
File "/config/custom_components/ics_calendar/calendar.py", line 78, in _async_setup_entry_bg_task
entity = ICSCalendarEntity(
File "/config/custom_components/ics_calendar/calendar.py", line 156, in __init__
self.data = ICSCalendarData(device_data)
File "/config/custom_components/ics_calendar/calendar.py", line 272, in __init__
self._calendar_data.set_headers(
File "/config/custom_components/ics_calendar/calendardata.py", line 134, in set_headers
self._opener = build_opener(
franc6 commented 1 week ago

OK, I'm guessing something changed in HA that I need to track down.

Previously, the way to fix the warning was to move the blocking call into a separate thread by calling it through HomeAssistant.async_create_task(). _async_setup_entry_bg_task is a method I added that's only ever called through async_create_task(), for the express purpose of making sure the blocking call won't block the event loop. So the trace there indicates the problem should be fixed. :(

Rudd-O commented 1 week ago

To my understanding what should be avoided is blocking I/O file calls. That's what's tripping the whole thing up.