rust.sync_dns_lookup
Stability
High
Detects synchronous DNS lookups that block async runtimes.
Why It Matters
Section titled “Why It Matters”Sync DNS in async:
- Blocks runtime — Entire thread pool stalled
- Unpredictable latency — DNS can take seconds
- Causes timeouts — Other tasks starved
Example
Section titled “Example”// ❌ 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?}What Unfault Detects
Section titled “What Unfault Detects”- std::net DNS resolution in async fns
- gethostbyname in async context
- Blocking resolvers in tokio code
Auto-Fix
Section titled “Auto-Fix”Unfault can replace with tokio::net::lookup_host.