diff --git a/Cargo.lock b/Cargo.lock index 2f7ebb1484..4c3bdb26af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1142,9 +1142,9 @@ dependencies = [ [[package]] name = "rand" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" dependencies = [ "libc", "rand_chacha", @@ -1789,6 +1789,7 @@ dependencies = [ "log", "lru-cache", "parking_lot", + "rand", "resolv-conf", "rustls", "serde", diff --git a/crates/resolver/Cargo.toml b/crates/resolver/Cargo.toml index 249921cfc6..786634c368 100644 --- a/crates/resolver/Cargo.toml +++ b/crates/resolver/Cargo.toml @@ -72,6 +72,7 @@ lazy_static = "1.0" log = "0.4" lru-cache = "0.1.2" parking_lot = "0.11" +rand = "0.8.4" resolv-conf = { version = "0.7.0", optional = true, features = ["system"] } rustls = {version = "0.19", optional = true} serde = { version = "1.0", features = ["derive"], optional = true } diff --git a/crates/resolver/src/name_server/name_server_pool.rs b/crates/resolver/src/name_server/name_server_pool.rs index 8b1b4a1852..40dcbe2340 100644 --- a/crates/resolver/src/name_server/name_server_pool.rs +++ b/crates/resolver/src/name_server/name_server_pool.rs @@ -13,6 +13,7 @@ use std::time::Duration; use futures_util::stream::{FuturesUnordered, StreamExt}; use futures_util::{future::Future, future::FutureExt}; +use rand::{seq::SliceRandom, thread_rng as rng}; use smallvec::SmallVec; use proto::xfer::{DnsHandle, DnsRequest, DnsResponse}; @@ -304,6 +305,9 @@ where loop { let request_cont = request.clone(); + // Shuffe DNS NameServers to avoid overloads to the first configured ones + conns.shuffle(&mut rng()); + // construct the parallel requests, 2 is the default let mut par_conns = SmallVec::<[NameServer; 2]>::new(); let count = conns.len().min(opts.num_concurrent_reqs.max(1));