-
Notifications
You must be signed in to change notification settings - Fork 258
fix: add timeout for DNS failures #6972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
0daa96d
5db0dc9
fdfaf17
b88e746
f77f6f0
d932ce9
0ec06ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,16 +74,26 @@ impl Default for PeerSeedsConfig { | |
| Self { | ||
| override_from: None, | ||
| peer_seeds: StringList::default(), | ||
| dns_seeds: vec![format!( | ||
| "seeds.{}.tari.com", | ||
| Network::get_current_or_user_setting_or_default().as_key_str() | ||
| )] | ||
| dns_seeds: vec![ | ||
| format!( | ||
| "seeds.{}.tari.com", | ||
| Network::get_current_or_user_setting_or_default().as_key_str() | ||
| ), | ||
| format!( | ||
| "ip4.seeds.{}.tari.com", | ||
| Network::get_current_or_user_setting_or_default().as_key_str() | ||
| ), | ||
| format!( | ||
| "ip6.seeds.{}.tari.com", | ||
| Network::get_current_or_user_setting_or_default().as_key_str() | ||
| ), | ||
| ] | ||
| .into(), | ||
| dns_seed_name_servers: DnsNameServerList::from_str( | ||
| "system, 1.1.1.1:853/cloudflare-dns.com, 8.8.8.8:853/dns.google, 9.9.9.9:853/dns.quad9.net", | ||
| ) | ||
| .expect("string is valid"), | ||
| dns_seeds_use_dnssec: false, | ||
| dns_seeds_use_dnssec: true, | ||
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,7 +76,10 @@ use tari_storage::{ | |
| LMDBWrapper, | ||
| }; | ||
| use thiserror::Error; | ||
| use tokio::sync::{broadcast, mpsc}; | ||
| use tokio::{ | ||
| sync::{broadcast, mpsc}, | ||
| time::timeout, | ||
| }; | ||
| use tower::ServiceBuilder; | ||
|
|
||
| use crate::{ | ||
|
|
@@ -508,7 +511,20 @@ impl P2pInitializer { | |
| P2pInitializer::get_dns_seed_resolver(config.dns_seeds_use_dnssec, &config.dns_seed_name_servers).await?; | ||
| let resolving = config.dns_seeds.iter().map(|addr| { | ||
| let mut resolver = resolver.clone(); | ||
| async move { (resolver.resolve(addr).await, addr) } | ||
| async move { | ||
| let timer = Instant::now(); | ||
| let seeds_res = match timeout(Duration::from_secs(5), resolver.resolve(addr)).await { | ||
| Ok(res) => res, | ||
| Err(_) => { | ||
| warn!(target: LOG_TARGET, "Timeout resolving DNS seed `{}`", addr); | ||
| Err(DnsClientError::Timeout) | ||
| }, | ||
| }; | ||
| // let res = (resolver.resolve(addr).await, addr); | ||
| let res = (seeds_res, addr.clone()); | ||
| info!(target: LOG_TARGET, "Resolved DNS seed `{}` in {:.0?}", addr, timer.elapsed()); | ||
| res | ||
| } | ||
| }); | ||
|
|
||
| let peers = future::join_all(resolving) | ||
|
|
@@ -549,26 +565,38 @@ impl P2pInitializer { | |
| } | ||
| let mut dns_errors = Vec::new(); | ||
| for dns in dns_seed_name_servers { | ||
| info!(target: LOG_TARGET, "Connecting to DNS name server: {}", dns); | ||
| let res = match (dns_seeds_use_dnssec, dns == &DnsNameServer::System) { | ||
| (true, false) => DnsSeedResolver::connect_secure(dns.clone()).await, | ||
| (_, _) => DnsSeedResolver::connect(dns.clone()).await, | ||
| (true, false) => timeout(Duration::from_secs(5), DnsSeedResolver::connect_secure(dns.clone())).await, | ||
|
||
| (_, _) => timeout(Duration::from_secs(5), DnsSeedResolver::connect(dns.clone())).await, | ||
| }; | ||
| match res { | ||
| Ok(val) => { | ||
| trace!(target: LOG_TARGET, "Found DNS client at '{}'", dns); | ||
| return Ok(val); | ||
| }, | ||
| Err(err) => { | ||
| warn!( | ||
| target: LOG_TARGET, | ||
| "DNS entry '{}' did not respond, trying the next one. You can edit 'dns_seed_name_servers' in \ | ||
| the config file. (Error: {})", | ||
| dns, | ||
| err.to_string(), | ||
| ); | ||
| Ok(Ok(resolver)) => return Ok(resolver), | ||
| Ok(Err(err)) => { | ||
| warn!(target: LOG_TARGET, "Failed to connect to DNS name server: {}", err); | ||
| dns_errors.push(err.to_string()) | ||
| }, | ||
| Err(_) => { | ||
| warn!(target: LOG_TARGET, "Timed out connecting to DNS name server: {}", dns); | ||
| dns_errors.push("Timeout".to_string()) | ||
| }, | ||
| } | ||
| // match res { | ||
| // Ok(val) => { | ||
| // trace!(target: LOG_TARGET, "Found DNS client at '{}'", dns); | ||
| // return Ok(val); | ||
| // }, | ||
| // Err(err) => { | ||
| // warn!( | ||
| // target: LOG_TARGET, | ||
| // "DNS entry '{}' did not respond, trying the next one. You can edit 'dns_seed_name_servers' in | ||
| // \ the config file. (Error: {})", | ||
| // dns, | ||
| // err.to_string(), | ||
| // ); | ||
| // dns_errors.push(err.to_string()) | ||
| // }, | ||
| // } | ||
SWvheerden marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| Err(ServiceInitializationError::from(DnsClientError::Connection(format!( | ||
| "{:?}", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can also add
tor.seeds.{}.tari.com, if we want to pull as many nodes?