Skip to content

Commit

Permalink
net: retry if GetAddrInfoW returns WSTRY_AGAIN when resolving an IP
Browse files Browse the repository at this point in the history
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 <[email protected]>
Auto-Submit: Bryan Mills <[email protected]>
Reviewed-by: Quim Muntal <[email protected]>
Run-TryBot: Quim Muntal <[email protected]>
Reviewed-by: Michael Pratt <[email protected]>
Reviewed-by: Bryan Mills <[email protected]>
  • Loading branch information
zen37 authored and gopherbot committed Feb 15, 2023
1 parent 2994e9a commit 87366fe
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/net/lookup_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 87366fe

Please sign in to comment.