]> Cypherpunks repositories - gostls13.git/commitdiff
net: retry if GetAddrInfoW returns WSTRY_AGAIN when resolving an IP
authorzen <mobi2009ro@gmail.com>
Tue, 17 Jan 2023 03:52:03 +0000 (19:52 -0800)
committerGopher Robot <gobot@golang.org>
Wed, 15 Feb 2023 22:27:16 +0000 (22:27 +0000)
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>
src/net/lookup_windows.go

index 4ee728196b31e424397f6854e245163ec05dad23..11f43fe1c7b63b547fb758aa8a7c20ca01140554 100644 (file)
@@ -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}