-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: retry on DNS queries. #1180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ import ( | |
| "sync" | ||
| "time" | ||
|
|
||
| "github.com/cenkalti/backoff/v4" | ||
| "github.com/go-acme/lego/v3/log" | ||
| "github.com/miekg/dns" | ||
| ) | ||
|
|
||
|
|
@@ -229,15 +231,39 @@ func dnsQuery(fqdn string, rtype uint16, nameservers []string, recursive bool) ( | |
| m := createDNSMsg(fqdn, rtype, recursive) | ||
|
|
||
| var in *dns.Msg | ||
| var err error | ||
| var errG error | ||
|
|
||
| for _, ns := range nameservers { | ||
| in, err = sendDNSQuery(m, ns) | ||
| if err == nil && len(in.Answer) > 0 { | ||
| bo := backoff.NewExponentialBackOff() | ||
| bo.Multiplier = 1.2 | ||
| bo.InitialInterval = dnsTimeout | ||
| bo.MaxInterval = 2 * bo.InitialInterval | ||
| bo.MaxElapsedTime = 4 * bo.InitialInterval | ||
|
Comment on lines
+239
to
+241
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sets the max. wait time to 2 minutes if I invoke lego with
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The initial interval must be the same as the timeout use by the DNS client. The Currently
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I see. Then the documentation of the Alternatively, we can reduce the default timeout down to something like 2 or 3s to approximate the previous behaviour (on that note, this should work in most cases, because DNS usually resolves fast enough). To accommodate #1008, we could also bump
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can reduce the default timeout. But I think that multiply by 10 or 20 is too big: the dnsQuery is used by several functions in a loop (by example a loop on ns) and this can become very very long.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I've missed the context; I thought this was part of the |
||
|
|
||
| operation := func() error { | ||
| var err error | ||
| in, err = sendDNSQuery(m, ns) | ||
|
|
||
| // errors from miekg/dns package and some errors from the net package must stop the retry. | ||
| var e *dns.Error | ||
| if err != nil && | ||
| (strings.Contains(err.Error(), "connection refused") || errors.As(err, &e)) { | ||
| return backoff.Permanent(err) | ||
| } | ||
|
|
||
| return err | ||
| } | ||
|
|
||
| notify := func(err error, d time.Duration) { | ||
| log.Infof("dnsQuery retry %v: fqdn=%s, ns=%s: %v", d, fqdn, ns, err) | ||
| } | ||
|
|
||
| errG = backoff.RetryNotify(operation, bo, notify) | ||
| if errG == nil && len(in.Answer) > 0 { | ||
| break | ||
| } | ||
| } | ||
| return in, err | ||
| return in, errG | ||
| } | ||
|
|
||
| func createDNSMsg(fqdn string, rtype uint16, recursive bool) *dns.Msg { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.