Closed mvdwetering closed 2 weeks ago
The loop parameter is deprecated in nearly everywhere in asyncio, and doesn't look like it exists on TCPConnector in master, so I'd avoid doing this. At a glance, I also don't see any blocking I/O in ClientSession that the comment refers to, I think it might just be the SSLContext that might be a little slow to create.
@bdraco Are you seeing things like this in homeassistant?
Ah, I did not know about loop parameter being deprecated.
I got to this state due to a "Detected blocking call" warning from Home Assistant 2024.9.0rc after which I started wrapping things into an executor (without knowing too much about them) which gave me an error that the BaseConnector could not figure out current loop, which lead to me adding loop
parameter which in turn lead to aiodns complaining about the same not being able to find current loop. Which made me end up here
Looking better at the warning from Home Assistant it indeed shows the SSL context.load_verify_locations
as offender. I initially just looked at the stacktrace and started wrapping all in the last function into an exectuor. So too much in make-errors-go-away-mode and not enough thinking :/
I just now tried wrapping only the SSL context in an executor and that works (and does not need a loop) So my initial problem is solved (sorry for getting off-topic a bit)
But I guess not passing on the loop parameter to aiodns.DNSResolve
is technically still an issue?
Its only load_verify_locations
https://developers.home-assistant.io/docs/asyncio_blocking_operations#load_verify_locations that needs to be run in the executor. Most aiohttp objects should be created in the event loop thread.
But I guess not passing on the loop parameter to
aiodns.DNSResolve
is technically still an issue?
When the loop param going away in most places, it likely something we wouldn't want to add support for.
Even if aiodns has a loop parameter, I'd expect them to remove it at some point as we have done, and as they are on a different release schedule to us, that'd just end up breaking it again. So, probably not much point in us passing the loop through.
Describe the bug
I am trying to use a TCPConnector with
loop
parameter. This resulted in this error.So
aiodns
can't get current loop, but that should have been passed in.Looking through the code it seems that the loop parameter is not passed on when creating the
aiodns.DNSResolver
hereI could not figure out how to build/install aiohttp from source, but by manually changing the file in the site-packages dir in my venv to pass on the loop like below it works.
To Reproduce
I am not entirely sure.
I think it is because I provide a TCPConnector to the session in which I provide the loop parameter which later on fails with the DNS lookup.
I tried to modify the sample in the readme for a minimal reproduction example, but could not get it to trigger :(
Also the issue does not trigger in my library example, it does trigger when the library is used from Home Assistant, not sure why.
This is the code that builds the clientsession
Expected behavior
Can provide loop to TCPCOnnector and gets used.
Logs/tracebacks
Python Version
aiohttp Version
multidict Version
yarl Version
OS
Ubuntu 22.04 in WSL
Related component
Client
Additional context
No response
Code of Conduct