Skip to content

Commit 4bf8247

Browse files
authored
Fallback to Google DNS in resolver initialization (#315)
* Fallback to Google DNS in resolver initialization If the default TokioResolver builder fails, the resolver now falls back to using Google's DNS configuration. This improves reliability in environments where the system DNS configuration may be unavailable or invalid. * Add warning when falling back to Google DNS A tracing warning is now logged if the system DNS resolver is unavailable and the resolver falls back to using Google DNS. This improves visibility into resolver configuration issues.
1 parent 90b964f commit 4bf8247

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

azalea-protocol/src/resolve.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ use std::{
66
};
77

88
pub use hickory_resolver::ResolveError;
9-
use hickory_resolver::{Name, TokioResolver, name_server::TokioConnectionProvider};
9+
use hickory_resolver::{
10+
Name, TokioResolver, config::ResolverConfig, name_server::TokioConnectionProvider,
11+
};
12+
use tracing::warn;
1013

1114
use crate::address::ServerAddr;
1215

@@ -16,7 +19,13 @@ pub type ResolverError = ResolveError;
1619

1720
static RESOLVER: LazyLock<TokioResolver> = LazyLock::new(|| {
1821
TokioResolver::builder(TokioConnectionProvider::default())
19-
.unwrap()
22+
.unwrap_or_else(|_| {
23+
warn!("System DNS resolver unavailable; falling back to Google DNS.");
24+
TokioResolver::builder_with_config(
25+
ResolverConfig::google(),
26+
TokioConnectionProvider::default(),
27+
)
28+
})
2029
.build()
2130
});
2231

0 commit comments

Comments
 (0)