Skip to content

Commit

Permalink
net: set DNSError.IsTemorary from addrinfoErrno errors
Browse files Browse the repository at this point in the history
DNSErrors that are created via addrinfoErrno(...) currently do not
have the "IsTemporary" set. However the addrinfoErrno type itself
has the Temporary() property.

This PR sets DNSError.IsTemporary to the addrinfoErrno.Temporary
value. This is useful to e.g. detect if a DNSError is of type
EAI_AGAIN (which is currently not possible AFAICT).
  • Loading branch information
mvo5 committed Apr 26, 2019
1 parent f30c564 commit ced7238
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/net/cgo_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,17 @@ func cgoLookupServicePort(hints *C.struct_addrinfo, network, service string) (po
var res *C.struct_addrinfo
gerrno, err := C.getaddrinfo(nil, (*C.char)(unsafe.Pointer(&cservice[0])), hints, &res)
if gerrno != 0 {
isTemporary := false
switch gerrno {
case C.EAI_SYSTEM:
if err == nil { // see golang.org/issue/6232
err = syscall.EMFILE
}
default:
err = addrinfoErrno(gerrno)
isTemporary = addrinfoErrno(gerrno).Temporary()
}
return 0, &DNSError{Err: err.Error(), Name: network + "/" + service}
return 0, &DNSError{Err: err.Error(), Name: network + "/" + service, IsTemporary: isTemporary}
}
defer C.freeaddrinfo(res)

Expand Down Expand Up @@ -159,6 +161,7 @@ func cgoLookupIPCNAME(network, name string) (addrs []IPAddr, cname string, err e
gerrno, err := C.getaddrinfo((*C.char)(unsafe.Pointer(&h[0])), nil, &hints, &res)
if gerrno != 0 {
isErrorNoSuchHost := false
isTemporary := false
switch gerrno {
case C.EAI_SYSTEM:
if err == nil {
Expand All @@ -176,9 +179,10 @@ func cgoLookupIPCNAME(network, name string) (addrs []IPAddr, cname string, err e
isErrorNoSuchHost = true
default:
err = addrinfoErrno(gerrno)
isTemporary = addrinfoErrno(gerrno).Temporary()
}

return nil, "", &DNSError{Err: err.Error(), Name: name, IsNotFound: isErrorNoSuchHost}
return nil, "", &DNSError{Err: err.Error(), Name: name, IsNotFound: isErrorNoSuchHost, IsTemporary: isTemporary}
}
defer C.freeaddrinfo(res)

Expand Down Expand Up @@ -299,15 +303,17 @@ func cgoLookupAddrPTR(addr string, sa *C.struct_sockaddr, salen C.socklen_t) (na
}
}
if gerrno != 0 {
isTemporary := false
switch gerrno {
case C.EAI_SYSTEM:
if err == nil { // see golang.org/issue/6232
err = syscall.EMFILE
}
default:
err = addrinfoErrno(gerrno)
isTemporary = addrinfoErrno(gerrno).Temporary()
}
return nil, &DNSError{Err: err.Error(), Name: addr}
return nil, &DNSError{Err: err.Error(), Name: addr, IsTemporary: isTemporary}
}
for i := 0; i < len(b); i++ {
if b[i] == 0 {
Expand Down

0 comments on commit ced7238

Please sign in to comment.