diff --git a/net/dnscache/dnscache.go b/net/dnscache/dnscache.go index 0983ae875..0a8b76a99 100644 --- a/net/dnscache/dnscache.go +++ b/net/dnscache/dnscache.go @@ -169,6 +169,7 @@ func (r *Resolver) ttl() time.Duration { } var debug = envknob.RegisterBool("TS_DEBUG_DNS_CACHE") +var noDNSFallback = envknob.RegisterBool("TS_NO_DNS_FALLBACK") // debugLogging allows enabling debug logging at runtime, via // SetDebugLoggingEnabled. @@ -302,7 +303,7 @@ func (r *Resolver) lookupIP(host string) (ip, ip6 netip.Addr, allIPs []netip.Add ips, err = resolver.LookupNetIP(ctx, "ip", host) } } - if (err != nil || len(ips) == 0) && r.LookupIPFallback != nil { + if (err != nil || len(ips) == 0) && r.LookupIPFallback != nil && !noDNSFallback() { ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() if err != nil { @@ -451,6 +452,12 @@ func (d *dialer) shouldTryBootstrap(ctx context.Context, err error, dc *dialCall d.dnsCache.dlogf("not using bootstrap DNS: no fallback") return false } + if noDNSFallback() { + if debug() { + log.Printf("dnscache: not using bootstrap DNS: disabled via TS_NO_DNS_FALLBACK") + } + return false + } // We can't retry if the context is canceled, since any further // operations with this context will fail.