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