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
for {
newIPs, err := lookupIP(ctx, host)
if err != nil {
return nil, err
newIPs, newErr := lookupIP(ctx, host)
if err == nil {
err = newErr // it's fine to fail some of the resolutions
}
for _, ip := range newIPs {
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))
for key := range uniqueIPs {
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 ips, nil
return ips, err
}

View File

@@ -20,12 +20,17 @@ func Test_resolveRepeat(t *testing.T) {
ips []net.IP
err error
}{
"failure": {
lookupIPResult: [][]net.IP{
{{1, 1, 1, 1}, {1, 1, 1, 2}},
},
"failure twice": {
lookupIPResult: [][]net.IP{{}, {}},
lookupIPErr: fmt.Errorf("feeling sick"),
n: 1,
n: 2,
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": {