mirror of
https://github.com/golang/go
synced 2024-11-18 01:54:45 -07:00
net: retry if GetAddrInfoW returns WSTRY_AGAIN when resolving an IP
GetAddrInfoW is retried now multiple times as per the timeout and number of retries defined in func dnsReadConfig (before it was called only once) Fixes #55050 Change-Id: If5369ebb164d98557a802de938756dbf9c125773 Reviewed-on: https://go-review.googlesource.com/c/go/+/462051 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Reviewed-by: Quim Muntal <quimmuntal@gmail.com> Run-TryBot: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
This commit is contained in:
parent
2994e9aa79
commit
87366feb12
@ -10,10 +10,14 @@ import (
|
||||
"os"
|
||||
"runtime"
|
||||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const _WSAHOST_NOT_FOUND = syscall.Errno(11001)
|
||||
const (
|
||||
_WSAHOST_NOT_FOUND = syscall.Errno(11001)
|
||||
_WSATRY_AGAIN = syscall.Errno(11002)
|
||||
)
|
||||
|
||||
func winError(call string, err error) error {
|
||||
switch err {
|
||||
@ -118,7 +122,17 @@ func (r *Resolver) lookupIP(ctx context.Context, network, name string) ([]IPAddr
|
||||
if err != nil {
|
||||
return nil, &DNSError{Name: name, Err: err.Error()}
|
||||
}
|
||||
e := syscall.GetAddrInfoW(name16p, nil, &hints, &result)
|
||||
|
||||
dnsConf := getSystemDNSConfig()
|
||||
start := time.Now()
|
||||
|
||||
var e error
|
||||
for i := 0; i < dnsConf.attempts; i++ {
|
||||
e = syscall.GetAddrInfoW(name16p, nil, &hints, &result)
|
||||
if e == nil || e != _WSATRY_AGAIN || time.Since(start) > dnsConf.timeout {
|
||||
break
|
||||
}
|
||||
}
|
||||
if e != nil {
|
||||
err := winError("getaddrinfow", e)
|
||||
dnsError := &DNSError{Err: err.Error(), Name: name}
|
||||
|
Loading…
Reference in New Issue
Block a user