1
0
Fork 0
mirror of https://github.com/Luzifer/rootzone.git synced 2024-11-08 07:50:07 +00:00

Add retries to all DNS calls

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-06-22 20:03:17 +02:00
parent 7896e20f7f
commit 213e724e1b
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
3 changed files with 61 additions and 12 deletions

13
iana.go
View file

@ -42,9 +42,16 @@ func getIANAZoneMasters(tld string) ([]string, error) {
m := new(dns.Msg)
m.SetQuestion(tld, dns.TypeNS)
r, _, err := c.Exchange(m, getRandomInternicRoot())
if err != nil {
return nil, errors.Wrap(err, "Could not query nameservers")
var (
err error
r *dns.Msg
)
if err = retry(func() error {
r, _, err = c.Exchange(m, getRandomInternicRoot())
return errors.Wrap(err, "Could not query nameservers")
}); err != nil {
return nil, err
}
if r.Rcode != dns.RcodeSuccess {

View file

@ -13,9 +13,16 @@ func getOpenNICTLDs() ([]string, error) {
m := new(dns.Msg)
m.SetQuestion("tlds.opennic.glue.", dns.TypeTXT)
r, _, err := c.Exchange(m, cfg.OpenNICRoot+":53")
if err != nil {
return nil, errors.Wrap(err, "Could not query nameservers")
var (
err error
r *dns.Msg
)
if err = retry(func() error {
r, _, err = c.Exchange(m, cfg.OpenNICRoot+":53")
return errors.Wrap(err, "Could not query nameservers")
}); err != nil {
return nil, err
}
if r.Rcode != dns.RcodeSuccess {
@ -42,9 +49,16 @@ func getOpenNICZoneMasters(tld string) ([]string, error) {
m := new(dns.Msg)
m.SetQuestion(tld+"opennic.glue.", dns.TypeCNAME)
r, _, err := c.Exchange(m, cfg.OpenNICRoot+":53")
if err != nil {
return nil, errors.Wrap(err, "Could not query nameservers")
var (
err error
r *dns.Msg
)
if err = retry(func() error {
r, _, err = c.Exchange(m, cfg.OpenNICRoot+":53")
return errors.Wrap(err, "Could not query nameservers")
}); err != nil {
return nil, err
}
if r.Rcode != dns.RcodeSuccess {
@ -65,9 +79,11 @@ func getOpenNICZoneMasters(tld string) ([]string, error) {
m = new(dns.Msg)
m.SetQuestion(master, dns.TypeA)
r, _, err := c.Exchange(m, cfg.OpenNICRoot+":53")
if err != nil {
return nil, errors.Wrap(err, "Could not query nameservers")
if err = retry(func() error {
r, _, err = c.Exchange(m, cfg.OpenNICRoot+":53")
return errors.Wrap(err, "Could not query nameservers")
}); err != nil {
return nil, err
}
if r.Rcode != dns.RcodeSuccess {

26
retry.go Normal file
View file

@ -0,0 +1,26 @@
package main
import (
"math"
"time"
)
const (
maxRetries = 5
retryDelay = 1.2
)
func retry(f func() error) error {
var err error
for i := 1; i <= maxRetries; i++ {
if err = f(); err == nil {
return nil
}
sleep := time.Duration(math.Pow(retryDelay, float64(i)) * float64(time.Second))
time.Sleep(sleep)
}
return err
}