Skip to content

Commit

Permalink
Enable happy eyeballs when using hickory-dns (seanmonstar#2378)
Browse files Browse the repository at this point in the history
Happy Eyeballs algorithm is implemented for hyper, however it is not
working correctly for IPv6 only hosts because the default resolver
option in hickory is `Ipv4ThenIpv6`, meaning it only sends AAAA queries
if it cannot resolve an IPv4 address. Thus the address list `hyper`
receives is almost always IPv4 only given most servers have an IPv4
address. To make the Happy Eyeballs algorithm work correctly, we need
the resolver to resolve both IP versions. This also aligns with the
default GAI resolver behavior for both glibc and musl.
  • Loading branch information
zeling authored and Nutomic committed Nov 7, 2024
1 parent 008bc54 commit 3581d9f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/dns/hickory.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! DNS resolution via the [hickory-resolver](https://github.com/hickory-dns/hickory-dns) crate
use hickory_resolver::{lookup_ip::LookupIpIntoIter, system_conf, TokioAsyncResolver};
use hickory_resolver::{
config::LookupIpStrategy, lookup_ip::LookupIpIntoIter, system_conf, TokioAsyncResolver,
};
use once_cell::sync::OnceCell;

use std::io;
Expand Down Expand Up @@ -46,13 +48,16 @@ impl Iterator for SocketAddrs {
}

/// Create a new resolver with the default configuration,
/// which reads from `/etc/resolve.conf`.
/// which reads from `/etc/resolve.conf`. The options are
/// overriden to look up for both IPv4 and IPv6 addresses
/// to work with "happy eyeballs" algorithm.
fn new_resolver() -> io::Result<TokioAsyncResolver> {
let (config, opts) = system_conf::read_system_conf().map_err(|e| {
let (config, mut opts) = system_conf::read_system_conf().map_err(|e| {
io::Error::new(
io::ErrorKind::Other,
format!("error reading DNS system conf: {e}"),
)
})?;
opts.ip_strategy = LookupIpStrategy::Ipv4AndIpv6;
Ok(TokioAsyncResolver::tokio(config, opts))
}

0 comments on commit 3581d9f

Please sign in to comment.