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

Only switch to TCP for a DNS query if response was truncated (configurable with an option) #1562

Merged
merged 2 commits into from
Oct 8, 2021

Conversation

peterthejohnston
Copy link
Contributor

@peterthejohnston peterthejohnston commented Oct 6, 2021

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

@codecov
Copy link

codecov bot commented Oct 6, 2021

Codecov Report

Merging #1562 (82ba817) into main (cb73fd9) will decrease coverage by 0.14%.
The diff coverage is 76.19%.

@@            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     

Copy link
Member

@bluejekyll bluejekyll left a 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() => {
Copy link
Member

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 }.

Copy link
Contributor Author

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 TCP
  • Err && try_tcp_on_error → retry over TCP
  • otherwise → go with the UDP result

@djc
Copy link
Collaborator

djc commented Oct 7, 2021

Yeah, I think this makes sense to be the default (and maybe even skip the option for now?).

@bluejekyll
Copy link
Member

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.

@peterthejohnston
Copy link
Contributor Author

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?

@peterthejohnston peterthejohnston changed the title Add option to ResolverOpts to only switch to TCP for a DNS query if response was truncated Only switch to TCP for a DNS query if response was truncated (configurable with an option) Oct 7, 2021
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.
Copy link
Member

@bluejekyll bluejekyll left a 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?

@peterthejohnston
Copy link
Contributor Author

Do you mind if I update the branch to main? or do you want to do that?

Just updated it, thanks!

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

Successfully merging this pull request may close these issues.

Allow resolver to switch to TCP for large messages without having to include TCP in name server pool
3 participants