-
Notifications
You must be signed in to change notification settings - Fork 519
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
Avoid instantiating Resolver when it is not necessary for DoH #1123
Conversation
If making a default resolver isn't appropriate for whatever reason, the API to https() methods has a resolver parameter. So in this case you could set resolver to I'm considering merging this PR because it's consistent with the bootstrap_address approach and is simple, but for the other issue, namely "what if the hostname in the URL is an IP address?" I prefer the "pass in a resolver" solution rather than more complexity, as this situation is atypical. Also if there is some other way we ought to be getting the DNS server addresses on Android, I'd consider having the resolver support that, much in the way that we get resolver info from the registry or WMI on Windows. |
If we call https() directly, it will not be a problem. However, this resolver parameter is not available if we call it indirectly via The situation that the hostname in the URL is an IP address actually is a common trick to bypass the firewall in the mainland of China. And also the well-know 1.1.1.1. |
This is going further than I wanted, but still looks ok other than the issues in the CI runs ("make type") and these lines:
I get why you unindented them, but they're going to cause problems in the case where a bootstrap address is provided, as then we will access parsed.port when we haven't parsed. I'm thinking these should be in the block doing the parsing. Also some additional work my be required to make mypy happy after fixing the thing it is currently unhappy about. |
mypy seems failed to detect By the way, I feel confused that the (remote) |
Mypy frequently misses situations where something can't be
As this gives the info mypy needs and fixes the problem more clearly. Re |
thanks! |
Currently, a Resolver with default settings is always instantiated when instantiating a DoH backend. e.g. :
dnspython/dns/_asyncio_backend.py
Lines 190 to 204 in 3fbb41a
The Resolver is used to resolve the IP address for the hostname of the DoH server address.
However, this is not always necessary.
For example, when bootstrap_address is present or hostname is already a IP address:
dnspython/dns/_asyncio_backend.py
Lines 154 to 166 in 3fbb41a
And it may potentially cause problems as the Resolver is instantiated with default settings.
For example,
/etc/resolv.conf
is not accessible in Termux (URenko/Accesser#187).This pr partially mitigated this issue by avoiding instantiating the Resolver when bootstrap_address is present.
Further fixes are required to fully resolve this issue.