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 <maisem@tailscale.com>
pull/4284/head
Maisem Ali 3 years ago committed by Maisem Ali
parent 8294915780
commit b45bb577a0

@ -312,7 +312,7 @@ func (d *dialer) DialContext(ctx context.Context, network, address string) (retC
defer func() { defer func() {
// On failure, consider that our DNS might be wrong and ask the DNS fallback mechanism for // On failure, consider that our DNS might be wrong and ask the DNS fallback mechanism for
// some other IPs to try. // 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 return
} }
ips, err := d.dnsCache.LookupIPFallback(ctx, host) ips, err := d.dnsCache.LookupIPFallback(ctx, host)

Loading…
Cancel
Save