home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.71k stars 30.84k forks source link

xmpp notify fails due to "context.load_default_certs(purpose) inside the event loop" #125531

Open ElGraz opened 2 months ago

ElGraz commented 2 months ago

The problem

When trying to send a notification via xmpp, the module fails with;

WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to load_default_certs with args (<ssl.SSLContext object at 0xffff2b54ac50>, <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 integration 'xmpp' at homeassistant/components/xmpp/notify.py, line 144: super().__init__(sender, password) (offender: /usr/local/lib/python3.12/ssl.py, line 713: context.load_default_certs(purpose)), please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+xmpp%22
For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#load_default_certs
Traceback (most recent call last):
  File "/opt/ha/bin/hass", line 8, in <module>
    sys.exit(main())
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/__main__.py", line 209, in main
    exit_code = runner.run(runtime_conf)
  File "/opt/ha/lib/python3.12/site-packages/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 1986, 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 "/opt/ha/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 462, in _handle_request
    resp = await request_handler(request)
  File "/opt/ha/lib/python3.12/site-packages/aiohttp/web_app.py", line 537, in _handle
    resp = await handler(request)
  File "/opt/ha/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware
    return await handler(request)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/components/http/ban.py", line 85, in ban_middleware
    return await handler(request)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/components/http/auth.py", line 242, in auth_middleware
    return await handler(request)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/components/websocket_api/http.py", line 55, in get
    return await WebSocketHandler(request.app[KEY_HASS], request).async_handle()
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/components/websocket_api/http.py", line 341, in async_handle
    await self._async_websocket_command_phase(connection, send_bytes_text)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/components/websocket_api/http.py", line 492, in _async_websocket_command_phase
    async_handle_str(command_msg_data)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/components/websocket_api/connection.py", line 229, in async_handle
    handler(self.hass, self, schema(msg))
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/components/websocket_api/decorators.py", line 47, in schedule_handler
    hass.async_create_background_task(
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/core.py", line 861, in async_create_background_task
    task = create_eager_task(target, name=name, loop=self.loop)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/util/async_.py", line 45, in create_eager_task
    return Task(coro, loop=loop, name=name, eager_start=True)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/components/websocket_api/decorators.py", line 28, in _handle_async_response
    await func(hass, connection, msg)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/components/websocket_api/commands.py", line 245, in handle_call_service
    response = await hass.services.async_call(
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/core.py", line 2761, in async_call
    response_data = await coro
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/core.py", line 2804, in _execute_service
    return await target(service_call)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 996, in entity_service_call
    single_response = await _handle_entity_call(
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/helpers/service.py", line 1062, in _handle_entity_call
    task = hass.async_run_hass_job(func, entity, data)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/core.py", line 940, in async_run_hass_job
    return self._async_add_hass_job(hassjob, *args, background=background)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/core.py", line 755, in _async_add_hass_job
    task = create_eager_task(
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/util/async_.py", line 45, in create_eager_task
    return Task(coro, loop=loop, name=name, eager_start=True)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/components/automation/__init__.py", line 311, in trigger_service_handler
    await entity.async_trigger(
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/components/automation/__init__.py", line 755, in async_trigger
    return await self.action_script.async_run(
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/helpers/script.py", line 1795, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/util/async_.py", line 45, in create_eager_task
    return Task(coro, loop=loop, name=name, eager_start=True)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/helpers/script.py", line 463, in async_run
    await self._async_step(log_exceptions=False)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/helpers/script.py", line 525, in _async_step
    await getattr(self, handler)()
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/helpers/script.py", line 764, in _async_call_service_step
    self._hass.async_create_task_internal(
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/core.py", line 829, in async_create_task_internal
    task = create_eager_task(target, name=name, loop=self.loop)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/util/async_.py", line 45, in create_eager_task
    return Task(coro, loop=loop, name=name, eager_start=True)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/core.py", line 2761, in async_call
    response_data = await coro
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/core.py", line 2804, in _execute_service
    return await target(service_call)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/components/notify/legacy.py", line 273, in _async_notify_message_service
    await self.async_send_message(**kwargs)
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/components/xmpp/notify.py", line 111, in async_send_message
    await async_send_message(
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/components/xmpp/notify.py", line 379, in async_send_message
    SendNotificationBot()
  File "/opt/ha/lib/python3.12/site-packages/homeassistant/components/xmpp/notify.py", line 144, in __init__
    super().__init__(sender, password)

What version of Home Assistant Core has the issue?

core-2024.9.1

What was the last working version of Home Assistant Core?

core-2024.9.1

What type of installation are you running?

Home Assistant Core

Integration causing the issue

Automation

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 2 months ago

Hey there @fabaff, @flowolf, mind taking a look at this issue as it has been labeled with an integration (xmpp) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `xmpp` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign xmpp` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


xmpp documentation xmpp source (message by IssueLinks)

red-black-bonsai commented 1 month ago

I'm running into the same issue on 2024.9.3:

2024-09-28 22:44:38.743 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to load_default_certs with args (<ssl.SSLContext object at 0x7f5bc9eed0>, <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 integration 'xmpp' at homeassistant/components/xmpp/notify.py, line 144: super().__init__(sender, password) (offender: /usr/local/lib/python3.12/ssl.py, line 713: context.load_default_certs(purpose)), please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+xmpp%22
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/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 462, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 537, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 85, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/http.py", line 55, in get
    return await WebSocketHandler(request.app[KEY_HASS], request).async_handle()
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/http.py", line 341, in async_handle
    await self._async_websocket_command_phase(connection, send_bytes_text)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/http.py", line 492, in _async_websocket_command_phase
    async_handle_str(command_msg_data)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/connection.py", line 229, in async_handle
    handler(self.hass, self, schema(msg))
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 47, in schedule_handler
    hass.async_create_background_task(
  File "/usr/src/homeassistant/homeassistant/core.py", line 861, in async_create_background_task
    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 "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 28, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 245, in handle_call_service
    response = await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 2761, in async_call
    response_data = await coro
  File "/usr/src/homeassistant/homeassistant/core.py", line 2804, in _execute_service
    return await target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 996, in entity_service_call
    single_response = await _handle_entity_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1062, in _handle_entity_call
    task = hass.async_run_hass_job(func, entity, data)
  File "/usr/src/homeassistant/homeassistant/core.py", line 940, in async_run_hass_job
    return self._async_add_hass_job(hassjob, *args, background=background)
  File "/usr/src/homeassistant/homeassistant/core.py", line 755, in _async_add_hass_job
    task = create_eager_task(
  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 "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 311, in trigger_service_handler
    await entity.async_trigger(
  File "/usr/src/homeassistant/homeassistant/components/automation/__init__.py", line 755, in async_trigger
    return await self.action_script.async_run(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1795, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
  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 "/usr/src/homeassistant/homeassistant/helpers/script.py", line 463, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 525, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 764, in _async_call_service_step
    self._hass.async_create_task_internal(
  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 "/usr/src/homeassistant/homeassistant/core.py", line 2761, in async_call
    response_data = await coro
  File "/usr/src/homeassistant/homeassistant/core.py", line 2804, in _execute_service
    return await target(service_call)
  File "/usr/src/homeassistant/homeassistant/components/notify/legacy.py", line 273, in _async_notify_message_service
    await self.async_send_message(**kwargs)
  File "/usr/src/homeassistant/homeassistant/components/xmpp/notify.py", line 111, in async_send_message
    await async_send_message(
  File "/usr/src/homeassistant/homeassistant/components/xmpp/notify.py", line 379, in async_send_message
    SendNotificationBot()
  File "/usr/src/homeassistant/homeassistant/components/xmpp/notify.py", line 144, in __init__
    super().__init__(sender, password)

In addition, when I manually run an automation that sends a Jabber message, I get this error AND the message is sent nonetheless.

2024-09-28 22:55:23.038 INFO (MainThread) [homeassistant.components.automation.my_automation] My automation: Running automation actions
2024-09-28 22:55:23.038 INFO (MainThread) [homeassistant.components.automation.my_automation] My automation: Executing step call service
2024-09-28 22:55:23.343 INFO (MainThread) [slixmpp.features.feature_mechanisms.mechanisms] Authentication failed: not-authorized
2024-09-28 22:55:23.558 INFO (MainThread) [slixmpp.features.feature_bind.bind] JID set to: myuser@somejabber.org/home-assistant
2024-09-28 22:55:23.695 INFO (MainThread) [slixmpp.xmlstream.xmlstream] connection_lost: (None,)

Not really sure what's going on here but hoping it helps somebody else :)

kafisc1 commented 1 month ago

I'm also running into the same issue here.,