From b45bb577a00b12072142b9904a4a380085a26a0a Mon Sep 17 00:00:00 2001 From: Maisem Ali Date: Thu, 24 Mar 2022 22:14:06 -0700 Subject: [PATCH] net/dnscache: do not call LookupIPFallback if the context was canceled. When the context is canceled, dc.dialOne returns an error from line 345. This causes the defer on line 312 to try to resolve the host again, which triggers a dns lookup of "127.0.0.1" from derp. Updates tailscale/corp#4475 Signed-off-by: Maisem Ali --- net/dnscache/dnscache.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/dnscache/dnscache.go b/net/dnscache/dnscache.go index a04831306..c1536e0ad 100644 --- a/net/dnscache/dnscache.go +++ b/net/dnscache/dnscache.go @@ -312,7 +312,7 @@ func (d *dialer) DialContext(ctx context.Context, network, address string) (retC defer func() { // On failure, consider that our DNS might be wrong and ask the DNS fallback mechanism for // some other IPs to try. - if ret == nil || d.dnsCache.LookupIPFallback == nil || dc.dnsWasTrustworthy() { + if ret == nil || ctx.Err() != nil || d.dnsCache.LookupIPFallback == nil || dc.dnsWasTrustworthy() { return } ips, err := d.dnsCache.LookupIPFallback(ctx, host)