-
Notifications
You must be signed in to change notification settings - Fork 191
Don't send AAAA DNS request when domain resolved to IPv4 address #153
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #153 +/- ##
==========================================
+ Coverage 91.52% 92.01% +0.49%
==========================================
Files 14 14
Lines 1664 1679 +15
Branches 230 235 +5
==========================================
+ Hits 1523 1545 +22
+ Misses 112 104 -8
- Partials 29 30 +1
Continue to review full report at Codecov.
|
|
For my understanding, what's the expectation here regarding code coverage reduction? The _connect function is barely covered by any existing tests. Is it expected that I first write new tests for the code to then base my patch on top? |
|
@booxter a test that verifies the functionality is always beneficial, also for future readers. For this use case you can use |
auvipy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for any proposed code changes, it is always suggested to have proper tests to verify the changes.
It should raise test coverage level for the method.
_connect should continue to iterate through entries returned by getaddrinfo until it succeeds, or until it depletes the list, at which point it raises socket.error.
There is no need to send both A and AAAA requests when connecting to a host since we are interested in a single address only. So if the host resolves into IPv4 address, we can skip request for AAAA since it will not be used anyway. This sounds like a minor optimization, but it comes as a huge win in case where DNS resolver is not configured for the requested host name, but the name is listed in /etc/hosts with a IPv4 address. In this case, resolution is very quick (the file is local, so no DNS request is sent), except for the fact that we still ask for AAAA record for the host name. A misconfigured DNS resolver can take time until it will time out the request (30 seconds is a common length for Linux), which is an unnecessary delay. This exact situation hit OpenStack TripleO CI where DNS was not configured, but resolution is implemented via /etc/hosts file which did not include IPv6 entries. OpenStack bug: https://bugs.launchpad.net/neutron/+bug/1696094
If it's raised, we do nothing.
|
The failure in apicheck doesn't seem related to the patch. |
|
@booxter thanks for adding the test cases! I was wondering though, perhaps this is not a problem to be solved within the |
|
@georgepsarakis for what I understand, gai.conf does not control whether resolver fetches all records from all sources, but only the sorting order of the result. It means that with family=0, the work executed by the resolver will be the same irrespective of the file contents, even though the result may have different order of matching records. What I try to achieve here is to avoid some of the work for resolver if a satisfying record is found already. In this way, I can avoid a remote DNS call for AAAA in case when /etc/hosts contains a ipv4 address, which is totally fine for amqp. An alternative could probably be making eventlet custom dns code to iterate through families one by one and yield results one by one if family=0 is passed, but even then we would need to introduce a change in amqp to short circuit the dns code on first successful record yielded from eventlet. Also it may be not compatible with stdlib getaddrinfo behavior that returns a list and not a generator. |
The logic became a bit hard to follow, so added a bunch of comments trying to explain the rationale behind the complexity, as well as give key for intent of specific code blocks.
Suggest it's a DNS resolution issue, not a generic connectivity problem.
booxter
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the PR.
There is no need to send both A and AAAA requests when connecting to a
host since we are interested in a single address only. So if the host
resolves into IPv4 address, we can skip request for AAAA since it will
not be used anyway.
This sounds like a minor optimization, but it comes as a huge win in
case where DNS resolver is not configured for the requested host name,
but the name is listed in /etc/hosts with a IPv4 address. In this case,
resolution is very quick (the file is local, so no DNS request is sent),
except for the fact that we still ask for AAAA record for the host name.
A misconfigured DNS resolver can take time until it will time out the
request (30 seconds is a common length for Linux), which is an
unnecessary delay.
This exact situation hit OpenStack TripleO CI where DNS was not
configured, but resolution is implemented via /etc/hosts file which did
not include IPv6 entries.
OpenStack bug: https://bugs.launchpad.net/neutron/+bug/1696094