Maintenance: updater DNS resolution more resilient

This commit is contained in:
Quentin McGaw
2021-03-05 22:46:14 +00:00
parent 83b5a9457a
commit 71de05dc68
2 changed files with 20 additions and 11 deletions

View File

@@ -88,9 +88,9 @@ func resolveRepeat(ctx context.Context, lookupIP lookupIPFunc, host string,
i := 0 i := 0
for { for {
newIPs, err := lookupIP(ctx, host) newIPs, newErr := lookupIP(ctx, host)
if err != nil { if err == nil {
return nil, err err = newErr // it's fine to fail some of the resolutions
} }
for _, ip := range newIPs { for _, ip := range newIPs {
key := ip.String() key := ip.String()
@@ -113,6 +113,10 @@ func resolveRepeat(ctx context.Context, lookupIP lookupIPFunc, host string,
} }
} }
if len(uniqueIPs) == 0 {
return nil, err
}
ips = make([]net.IP, 0, len(uniqueIPs)) ips = make([]net.IP, 0, len(uniqueIPs))
for key := range uniqueIPs { for key := range uniqueIPs {
ip := net.ParseIP(key) ip := net.ParseIP(key)
@@ -126,5 +130,5 @@ func resolveRepeat(ctx context.Context, lookupIP lookupIPFunc, host string,
return bytes.Compare(ips[i], ips[j]) < 1 return bytes.Compare(ips[i], ips[j]) < 1
}) })
return ips, nil return ips, err
} }

View File

@@ -20,13 +20,18 @@ func Test_resolveRepeat(t *testing.T) {
ips []net.IP ips []net.IP
err error err error
}{ }{
"failure": { "failure twice": {
lookupIPResult: [][]net.IP{ lookupIPResult: [][]net.IP{{}, {}},
{{1, 1, 1, 1}, {1, 1, 1, 2}}, lookupIPErr: fmt.Errorf("feeling sick"),
}, n: 2,
lookupIPErr: fmt.Errorf("feeling sick"), err: fmt.Errorf("feeling sick"),
n: 1, },
err: fmt.Errorf("feeling sick"), "failure once": {
lookupIPResult: [][]net.IP{{}, {{1, 1, 1, 1}}},
lookupIPErr: fmt.Errorf("feeling sick"),
n: 2,
ips: []net.IP{{1, 1, 1, 1}},
err: fmt.Errorf("feeling sick"),
}, },
"successful": { "successful": {
lookupIPResult: [][]net.IP{ lookupIPResult: [][]net.IP{