fix(net): Fix off-by-one error in DNS seed peer retries, and clarify logs (#6460)
* Fix off-by-one error in DNS seed peer retries, and clarify logs * Fix confusing variable names
This commit is contained in:
parent
00d46e1aa9
commit
47e331119c
|
@ -1,3 +1,5 @@
|
||||||
|
//! Configuration for Zebra's network communication.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
net::{IpAddr, SocketAddr},
|
net::{IpAddr, SocketAddr},
|
||||||
|
@ -24,7 +26,14 @@ mod tests;
|
||||||
|
|
||||||
/// The number of times Zebra will retry each initial peer's DNS resolution,
|
/// The number of times Zebra will retry each initial peer's DNS resolution,
|
||||||
/// before checking if any other initial peers have returned addresses.
|
/// before checking if any other initial peers have returned addresses.
|
||||||
const MAX_SINGLE_PEER_RETRIES: usize = 1;
|
///
|
||||||
|
/// After doing this number of retries of a failed single peer, Zebra will
|
||||||
|
/// check if it has enough peer addresses from other seed peers. If it has
|
||||||
|
/// enough addresses, it won't retry this peer again.
|
||||||
|
///
|
||||||
|
/// If the number of retries is `0`, other peers are checked after every successful
|
||||||
|
/// or failed DNS attempt.
|
||||||
|
const MAX_SINGLE_SEED_PEER_DNS_RETRIES: usize = 0;
|
||||||
|
|
||||||
/// Configuration for networking code.
|
/// Configuration for networking code.
|
||||||
#[derive(Clone, Debug, Serialize)]
|
#[derive(Clone, Debug, Serialize)]
|
||||||
|
@ -164,7 +173,7 @@ impl Config {
|
||||||
// address peers. Individual retries avoid this issue.
|
// address peers. Individual retries avoid this issue.
|
||||||
let peer_addresses = peers
|
let peer_addresses = peers
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| Config::resolve_host(s, MAX_SINGLE_PEER_RETRIES))
|
.map(|s| Config::resolve_host(s, MAX_SINGLE_SEED_PEER_DNS_RETRIES))
|
||||||
.collect::<futures::stream::FuturesUnordered<_>>()
|
.collect::<futures::stream::FuturesUnordered<_>>()
|
||||||
.concat()
|
.concat()
|
||||||
.await;
|
.await;
|
||||||
|
@ -188,12 +197,25 @@ impl Config {
|
||||||
///
|
///
|
||||||
/// If DNS continues to fail, returns an empty list of addresses.
|
/// If DNS continues to fail, returns an empty list of addresses.
|
||||||
async fn resolve_host(host: &str, max_retries: usize) -> HashSet<SocketAddr> {
|
async fn resolve_host(host: &str, max_retries: usize) -> HashSet<SocketAddr> {
|
||||||
for retry_count in 1..=max_retries {
|
for retries in 0..=max_retries {
|
||||||
match Config::resolve_host_once(host).await {
|
if let Ok(addresses) = Config::resolve_host_once(host).await {
|
||||||
Ok(addresses) => return addresses,
|
return addresses;
|
||||||
Err(_) => tracing::info!(?host, ?retry_count, "Retrying peer DNS resolution"),
|
}
|
||||||
};
|
|
||||||
tokio::time::sleep(DNS_LOOKUP_TIMEOUT).await;
|
if retries < max_retries {
|
||||||
|
tracing::info!(
|
||||||
|
?host,
|
||||||
|
previous_attempts = ?(retries + 1),
|
||||||
|
"Waiting {DNS_LOOKUP_TIMEOUT:?} to retry seed peer DNS resolution",
|
||||||
|
);
|
||||||
|
tokio::time::sleep(DNS_LOOKUP_TIMEOUT).await;
|
||||||
|
} else {
|
||||||
|
tracing::info!(
|
||||||
|
?host,
|
||||||
|
attempts = ?(retries + 1),
|
||||||
|
"Seed peer DNS resolution failed, checking for addresses from other seed peers",
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HashSet::new()
|
HashSet::new()
|
||||||
|
|
Loading…
Reference in New Issue