go.sync_dns_lookup
Performance
Medium
Detects synchronous DNS lookups that can block for seconds during resolution failures.
Why It Matters
Section titled “Why It Matters”Synchronous DNS:
- Blocks goroutines — DNS can take seconds to timeout
- Exhausts workers — Blocked goroutines can’t serve requests
- Cascades failures — DNS issues affect all requests
Example
Section titled “Example”// ❌ Before (synchronous)func connect(host string) error { addrs, err := net.LookupHost(host) // Can block for seconds if err != nil { return err } // ...}// ✅ After (with timeout)func connect(ctx context.Context, host string) error { resolver := &net.Resolver{} addrs, err := resolver.LookupHost(ctx, host) // Respects context timeout if err != nil { return err } // ...}What Unfault Detects
Section titled “What Unfault Detects”net.LookupHost()without contextnet.LookupAddr()without timeout- DNS lookups in critical paths
Auto-Fix
Section titled “Auto-Fix”Unfault adds context-aware DNS resolution:
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)defer cancel()
resolver := &net.Resolver{}addrs, err := resolver.LookupHost(ctx, host)