1
0
mirror of https://github.com/golang/go synced 2024-09-29 07:14:29 -06:00

net: report completed when context is done in cgoLookupIP and cgoLookupPTR

All the Lookup* methods that resolve hostnames eventually call lookupIP
or lookupHost method. When the order is selected to be hostLookupCGO
then lookupHost calls cgoLookupHost which internally calls cgoLookupIP
(the lookupIP directly calls cgoLookupIP).
When we provide a context that is cancelled after cgo call, then the
cgoLookupIP returns completed  == false, which caues the
lookupIP/lookupHost to fallback to the go resolver.
This fallback is unnecessary because our context is already cancelled.

The same thing can happen to LookupAddr.

Change-Id: Ifff7716c461f05d954ef43b5205865103558b410
GitHub-Last-Rev: 2ef2023e8c
GitHub-Pull-Request: golang/go#57042
Reviewed-on: https://go-review.googlesource.com/c/go/+/454696
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Mateusz Poliwczak 2022-12-03 13:50:45 +00:00 committed by Gopher Robot
parent d0851777da
commit 3dc85a32fc

View File

@ -222,7 +222,7 @@ func cgoLookupIP(ctx context.Context, network, name string) (addrs []IPAddr, err
case r := <-result:
return r.addrs, r.err, true
case <-ctx.Done():
return nil, mapErr(ctx.Err()), false
return nil, mapErr(ctx.Err()), true
}
}
@ -262,7 +262,7 @@ func cgoLookupPTR(ctx context.Context, addr string) (names []string, err error,
case r := <-result:
return r.names, r.err, true
case <-ctx.Done():
return nil, mapErr(ctx.Err()), false
return nil, mapErr(ctx.Err()), true
}
}