Retry DNS resolution on failure (#1762)

Otherwise, a transient DNS failure makes the node hang.
This commit is contained in:
teor 2021-02-18 07:09:02 +10:00 committed by GitHub
parent 86169f6412
commit 579bd4a368
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 14 deletions

View File

@ -38,6 +38,8 @@ impl Config {
/// If DNS resolution fails or times out for all peers, returns an empty list. /// If DNS resolution fails or times out for all peers, returns an empty list.
async fn parse_peers(peers: &HashSet<String>) -> HashSet<SocketAddr> { async fn parse_peers(peers: &HashSet<String>) -> HashSet<SocketAddr> {
use futures::stream::StreamExt; use futures::stream::StreamExt;
loop {
let peer_addresses = peers let peer_addresses = peers
.iter() .iter()
.map(|s| Config::resolve_host(s)) .map(|s| Config::resolve_host(s))
@ -46,13 +48,17 @@ impl Config {
.await; .await;
if peer_addresses.is_empty() { if peer_addresses.is_empty() {
tracing::warn!( tracing::info!(
?peers, ?peers,
?peer_addresses, ?peer_addresses,
"empty peer list after DNS resolution" "empty peer list after DNS resolution, retrying after {} seconds",
crate::constants::DNS_LOOKUP_TIMEOUT.as_secs()
); );
}; tokio::time::sleep(crate::constants::DNS_LOOKUP_TIMEOUT).await;
peer_addresses } else {
return peer_addresses;
}
}
} }
/// Get the initial seed peers based on the configured network. /// Get the initial seed peers based on the configured network.