-
Notifications
You must be signed in to change notification settings - Fork 432
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
Only switch to TCP for a DNS query if response was truncated (configurable with an option) #1562
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1562 +/- ##
==========================================
- Coverage 83.36% 83.22% -0.14%
==========================================
Files 172 172
Lines 17075 17088 +13
==========================================
- Hits 14233 14220 -13
- Misses 2842 2868 +26 |
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.
Overall, this looks really good. I wonder if we should make this be the default logic? There have been past complaints about slow timeouts/failures, and this is probably the reason.
See one comment I left.
@@ -238,23 +238,29 @@ where | |||
let udp_res = Self::try_send(opts, datagram_conns, request).await; | |||
|
|||
let udp_res = match udp_res { | |||
// handling promotion from datagram to stream base on truncation in message | |||
Ok(response) if !response.truncated() => { |
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.
I wonder if we should change this to be a positive check for is truncated vs. a not truncated. Looking at this, I'm actually really confused why I wrote it this way.
What d you think about having the default be Ok(response) => { return Ok(response); }
and then make the truncated check be Ok(response) if response.truncated() => { debug!(...); Ok(response }
.
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.
Yeah, I think that's much easier to follow. I've combined the default arms for both Ok
and Err
variants, so there are just three match arms:
Ok && truncated
→ retry over TCPErr && try_tcp_on_error
→ retry over TCP- otherwise → go with the UDP result
Yeah, I think this makes sense to be the default (and maybe even skip the option for now?). |
I think I'm ok with that... though there could be reasons that UDP is blocked on a network and TCP is not. |
Yeah, if we remove fallback to TCP on errors that also means that if a resolver is configured with only TCP name server(s), it won't use those to query, will always see a "No connections available" error, which seems undesirable. Maybe we should leave it in as an option, but default to go UDP unless we get a truncated response? |
Currently, if queries to name servers over UDP result in either a truncated response, or any kind of error, the query will be retried over TCP. It should be possible to only use TCP for the case of oversized messages, and avoid it in the common case. This change makes this the default behavior and adds an option to ResolverOpts that can be enabled to get the current behavior.
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.
This looks good to me. Do you mind if I update the branch to main? or do you want to do that?
Just updated it, thanks! |
Currently, if queries to name servers over UDP result in either a
truncated response, or any kind of error, the query will be retried over
TCP. It should be possible to only use TCP for the case of oversized
messages, and avoid it in the common case. This change makes this the
default behavior and adds an option to ResolverOpts that can be enabled
to get the current behavior.
Fixes #1561