Skip to content

go.sync_dns_lookup

Performance Medium

Detects synchronous DNS lookups that can block for seconds during resolution failures.

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
// ❌ 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
}
// ...
}
  • net.LookupHost() without context
  • net.LookupAddr() without timeout
  • DNS lookups in critical paths

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)