Skip to content

rust.sync_dns_lookup

Stability High

Detects synchronous DNS lookups that block async runtimes.

Sync DNS in async:

  • Blocks runtime — Entire thread pool stalled
  • Unpredictable latency — DNS can take seconds
  • Causes timeouts — Other tasks starved
// ❌ Before (blocking DNS lookup)
async fn connect_to_host(host: &str) -> TcpStream {
let addrs = std::net::ToSocketAddrs::to_socket_addrs(host)?; // Blocks!
TcpStream::connect(addrs.next().unwrap()).await?
}
// ✅ After (async DNS resolution)
use tokio::net::lookup_host;
async fn connect_to_host(host: &str) -> TcpStream {
let addrs = lookup_host(host).await?; // Non-blocking
TcpStream::connect(addrs.next().unwrap()).await?
}
  • std::net DNS resolution in async fns
  • gethostbyname in async context
  • Blocking resolvers in tokio code

Unfault can replace with tokio::net::lookup_host.