From 87366feb125008aadc85ace6ccbfd2213b640c9c Mon Sep 17 00:00:00 2001 From: zen Date: Mon, 16 Jan 2023 19:52:03 -0800 Subject: [PATCH] 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 Auto-Submit: Bryan Mills Reviewed-by: Quim Muntal Run-TryBot: Quim Muntal Reviewed-by: Michael Pratt Reviewed-by: Bryan Mills --- src/net/lookup_windows.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/net/lookup_windows.go b/src/net/lookup_windows.go index 4ee728196b31e4..11f43fe1c7b63b 100644 --- a/src/net/lookup_windows.go +++ b/src/net/lookup_windows.go @@ -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}