Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detected blocking call inside the event loop #133965

Open
Anto79-ops opened this issue Dec 24, 2024 · 11 comments · May be fixed by OpenXbox/xbox-webapi-python#113
Open

Detected blocking call inside the event loop #133965

Anto79-ops opened this issue Dec 24, 2024 · 11 comments · May be fixed by OpenXbox/xbox-webapi-python#113

Comments

@Anto79-ops
Copy link

The problem

hello

received this log upon updating to 2025.1.0b2

thanks

Logger: homeassistant.util.loop
Source: util/loop.py:136
First occurred: 9:14:05 AM (1 occurrences)
Last logged: 9:14:05 AM

Detected blocking call to load_verify_locations with args (<ssl.SSLContext object at 0x7f0de387ca70>,) inside the event loop by integration 'xbox' at homeassistant/components/xbox/api.py, line 17: super().__init__(SignedSession(), "", "", "") (offender: /usr/local/lib/python3.13/site-packages/httpx/_config.py, line 149: context.load_verify_locations(cafile=cafile)), please create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+xbox%22 For developers, please see https://developers.home-assistant.io/docs/asyncio_blocking_operations/#load_verify_locations 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 227, in <module> sys.exit(main()) File "/usr/src/homeassistant/homeassistant/__main__.py", line 213, in main exit_code = runner.run(runtime_conf) File "/usr/src/homeassistant/homeassistant/runner.py", line 154, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File "/usr/local/lib/python3.13/asyncio/base_events.py", line 707, in run_until_complete self.run_forever() File "/usr/local/lib/python3.13/asyncio/base_events.py", line 678, in run_forever self._run_once() File "/usr/local/lib/python3.13/asyncio/base_events.py", line 2033, in _run_once handle._run() File "/usr/local/lib/python3.13/asyncio/events.py", line 89, in _run self._context.run(self._callback, *self._args) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 788, in async_setup_locked await self.async_setup(hass, integration=integration) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 551, in async_setup await self.__async_setup_with_context(hass, integration) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 640, in __async_setup_with_context result = await component.async_setup_entry(hass, self) File "/usr/src/homeassistant/homeassistant/components/xbox/__init__.py", line 39, in async_setup_entry auth = api.AsyncConfigEntryAuth(session) File "/usr/src/homeassistant/homeassistant/components/xbox/api.py", line 17, in __init__ super().__init__(SignedSession(), "", "", "")

What version of Home Assistant Core has the issue?

2025.0.0b2

What was the last working version of Home Assistant Core?

not sure

What type of installation are you running?

Home Assistant OS

Integration causing the issue

No response

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
Copy link

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

Code owner commands

Code owners of xbox 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 xbox 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)


xbox documentation
xbox source
(message by IssueLinks)

@dcmeglio
Copy link
Contributor

@hunterjm I raised a PR for the underlying library that will allow us to pass in an SSLContext. This won't directly fix the issue, we need to change:
super().__init__(SignedSession(), "", "", "")
to
super().__init__(SignedSession(ssl_context=get_default_context()), "", "", "")

As well, which I have a PR ready to go for once a new version of the library is cut.

@joostlek
Copy link
Member

Hmm, ideally we use our own httpx client rather than theirs. But they expect a signed session and have that extended rather than wrapped

@dcmeglio
Copy link
Contributor

dcmeglio commented Dec 29, 2024

Agreed, but like you said, not the way the library is written. If you check the AuthenticationManager, it seems to have been an intentional change:

        if not isinstance(client_session, (SignedSession, httpx.AsyncClient)):
            raise DeprecationWarning(
                """Xbox WebAPI changed to use SignedSession (wrapped httpx.AsyncClient).
                Please check the documentation"""
            )

So my thought was, short of drastic changes to the library (that I don't even know if the author will accept -- this seems to be used by a lot more than just HA), this was a simple fix that at least eliminates the blocking IO and eliminates creating an extra SSL context.

@dcmeglio
Copy link
Contributor

dcmeglio commented Jan 3, 2025

My PR to the upstream library hasn't been reviewed yet so I don't think this is going to make it into the 2025.1 milestone

@linwiz
Copy link

linwiz commented Jan 9, 2025

I'm also experiencing this. I've manually updated the file xbox/webapi/common/signed_session.py on my installation to include this commit, however this didn't solve the warning message in the logs.

@dcmeglio
Copy link
Contributor

dcmeglio commented Jan 9, 2025

You can’t just overrwrite the file. Every time you run HA it’s going to overwrite your manual change with the original

@linwiz
Copy link

linwiz commented Jan 9, 2025

The changes I've made appear to have persisted a HA OS reboot. but I understand this is not the proper way to do these things.

@dcmeglio
Copy link
Contributor

dcmeglio commented Jan 9, 2025

Ok. As I mentioned though, that PR won’t fix the issue anyway. It adds the ability to fix it in HA but an HA change is needed. I can’t do that till the library pr is merged

@joostlek
Copy link
Member

joostlek commented Jan 9, 2025

I think it would work if we create the SignedSession in the executor I think.

But ideally we pass in our own httpx client to the library

@dcmeglio
Copy link
Contributor

We may have to go the executor route if we want this fixed, the library author still hasn't responded to my PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants