mirror of
https://github.com/golang/go
synced 2024-11-15 02:10:21 -07:00
net: fix lookupHost on Plan 9
CL 532217 added the newDNSError function. However, the implementation was not correct on Plan 9, which lead TestLookupNoSuchHost to fail. This change fixes lookupHost on Plan 9. Fixes #67096. Change-Id: I39271f7d588b19c1b1608f18a24d871460be09cd Reviewed-on: https://go-review.googlesource.com/c/go/+/582236 Reviewed-by: Joedian Reid <joedian@google.com> Run-TryBot: David du Colombier <0intro@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
cf164403d1
commit
16ce8b3925
@ -109,17 +109,11 @@ func queryDNS(ctx context.Context, addr string, typ string) (res []string, err e
|
||||
func handlePlan9DNSError(err error, name string) error {
|
||||
if stringsHasSuffix(err.Error(), "dns: name does not exist") ||
|
||||
stringsHasSuffix(err.Error(), "dns: resource does not exist; negrcode 0") ||
|
||||
stringsHasSuffix(err.Error(), "dns: resource does not exist; negrcode") {
|
||||
return &DNSError{
|
||||
Err: errNoSuchHost.Error(),
|
||||
Name: name,
|
||||
IsNotFound: true,
|
||||
}
|
||||
}
|
||||
return &DNSError{
|
||||
Err: err.Error(),
|
||||
Name: name,
|
||||
stringsHasSuffix(err.Error(), "dns: resource does not exist; negrcode") ||
|
||||
stringsHasSuffix(err.Error(), "dns failure") {
|
||||
err = errNoSuchHost
|
||||
}
|
||||
return newDNSError(err, name, "")
|
||||
}
|
||||
|
||||
// toLower returns a lower-case version of in. Restricting us to
|
||||
@ -169,10 +163,7 @@ func (*Resolver) lookupHost(ctx context.Context, host string) (addrs []string, e
|
||||
// host names in local network (e.g. from /lib/ndb/local)
|
||||
lines, err := queryCS(ctx, "net", host, "1")
|
||||
if err != nil {
|
||||
if stringsHasSuffix(err.Error(), "dns failure") {
|
||||
err = errNoSuchHost
|
||||
}
|
||||
return nil, newDNSError(err, host, "")
|
||||
return nil, handlePlan9DNSError(err, host)
|
||||
}
|
||||
loop:
|
||||
for _, line := range lines {
|
||||
|
@ -1634,6 +1634,10 @@ func TestLookupNoSuchHost(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDNSErrorUnwrap(t *testing.T) {
|
||||
if runtime.GOOS == "plan9" {
|
||||
// The Plan 9 implementation of the resolver doesn't use the Dial function yet. See https://go.dev/cl/409234
|
||||
t.Skip("skipping on plan9")
|
||||
}
|
||||
rDeadlineExcceeded := &Resolver{PreferGo: true, Dial: func(ctx context.Context, network, address string) (Conn, error) {
|
||||
return nil, context.DeadlineExceeded
|
||||
}}
|
||||
|
Loading…
Reference in New Issue
Block a user