mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-02-23 15:12:57 +08:00
commit901a3ac1c9
Author: Tom Limoncelli <tlimoncelli@stackoverflow.com> Date: Tue Jan 21 14:43:33 2025 -0500 CHORE: Update dependencies (#3397) commit70e9659014
Author: Tom Limoncelli <tlimoncelli@stackoverflow.com> Date: Tue Jan 21 14:29:53 2025 -0500 MSDNS: Provider is failing due to lint fix gone wrong (#3396) commit5e15bbe676
Author: Jakob Ackermann <das7pad@outlook.com> Date: Sat Jan 18 13:54:37 2025 +0000 BUG: fetch zones once in ZoneCache (#3394) commita631c5bfdd
Author: Kai Schwarz <kai.schwarz@centralnic.com> Date: Fri Jan 17 20:15:10 2025 +0100 CNR: Initial Performance improvement; golint review (#3391) commite1c9785159
Author: Tom Limoncelli <tlimoncelli@stackoverflow.com> Date: Fri Jan 17 07:11:10 2025 -0500 CHORE: Update dependencies (#3385) commit9e88b6a801
Author: Tom Limoncelli <tlimoncelli@stackoverflow.com> Date: Thu Jan 16 21:47:10 2025 -0500 CICD: Make pager tests more visible (#3387) commit67db0e287d
Author: Tom Limoncelli <tlimoncelli@stackoverflow.com> Date: Thu Jan 16 14:41:18 2025 -0500 GCLOUD: remove (irrelevant) slow test (#3384) commitc348e354ff
Author: Tom Limoncelli <tlimoncelli@stackoverflow.com> Date: Thu Jan 16 14:32:32 2025 -0500 GCLOUD: CICD: Skip the pager1201 integration test (#3383) commit5cfb9073a2
Author: Tom Limoncelli <tlimoncelli@stackoverflow.com> Date: Thu Jan 16 14:17:47 2025 -0500 TRANSIP: Pause when rate-limited (#3378) commitf666af8714
Author: Tom Limoncelli <tlimoncelli@stackoverflow.com> Date: Thu Jan 16 13:56:46 2025 -0500 GCLOUD: Re-try on 502 errors (#3376) commit1a1a4bf00d
Author: Tom Limoncelli <tlimoncelli@stackoverflow.com> Date: Thu Jan 16 12:54:48 2025 -0500 INWX: Enable SRV to have "." target (#3380) commit355643988e
Author: Tom Limoncelli <tlimoncelli@stackoverflow.com> Date: Thu Jan 16 10:58:11 2025 -0500 CLOUDFLAREAPI: No longer treat TTL=300 as special (#3368) Co-authored-by: Sukka <github@skk.moe> commit89c65b6683
Author: Tom Limoncelli <tlimoncelli@stackoverflow.com> Date: Thu Jan 16 10:03:00 2025 -0500 INWX: Permit "." target for SRV records (#3377) commitfc2c506920
Author: Tom Limoncelli <tlimoncelli@stackoverflow.com> Date: Wed Jan 15 18:28:15 2025 -0500 CICD: Warn user if -provider does not match profiles.json:TYPE (#3375) commit0d5b3c22b7
Author: Jakob Ackermann <das7pad@outlook.com> Date: Wed Jan 15 22:43:24 2025 +0000 CLOUDFLARE: adopt ZoneCache (#3373) commit2ef23621b5
Author: Jakob Ackermann <das7pad@outlook.com> Date: Wed Jan 15 20:23:02 2025 +0000 HETZNER: adopt ZoneCache (#3372) commitab00797f89
Author: Tom Hughes <tom@compton.nu> Date: Wed Jan 15 02:07:19 2025 +0000 FEATURE: Extend PTR magic handling to support RFC4183 names (#3364) commit5c9b17039e
Author: Jakob Ackermann <das7pad@outlook.com> Date: Wed Jan 15 02:05:17 2025 +0000 FEAT: Add ZoneCache primitive (#3365)
94 lines
2.7 KiB
Go
94 lines
2.7 KiB
Go
package gcloud
|
||
|
||
import (
|
||
"log"
|
||
"time"
|
||
|
||
"google.golang.org/api/googleapi"
|
||
)
|
||
|
||
const (
|
||
initialBackoff = time.Second * 10 // First delay duration
|
||
maxBackoff = time.Minute * 3 // Maximum backoff delay
|
||
)
|
||
|
||
// backoff is the amount of time to sleep if a 429 or 504 is received.
|
||
// It is doubled after each use.
|
||
var (
|
||
backoff = initialBackoff
|
||
backoff404 = false // Set if the last call requested a retry of a 404
|
||
backoff502 = false // Set if the last call requested a retry of a 502
|
||
)
|
||
|
||
func retryNeeded(resp *googleapi.ServerResponse, err error) bool {
|
||
if err == nil {
|
||
return false // Not an error.
|
||
}
|
||
|
||
serr, ok := err.(*googleapi.Error)
|
||
if !ok {
|
||
return false // Not a google error.
|
||
}
|
||
|
||
if serr.Code == 200 {
|
||
backoff = initialBackoff // Reset
|
||
return false // Success! No need to retry.
|
||
}
|
||
|
||
if serr.Code == 404 {
|
||
// serr.Code == 404 happens occasionally when GCLOUD hasn't
|
||
// finished updating the database yet. We pause and retry
|
||
// exactly once. There should be a better way to do this, such as
|
||
// a callback that would tell us a transaction is complete.
|
||
if backoff404 {
|
||
backoff404 = false
|
||
return false // Give up. We've done this already.
|
||
}
|
||
log.Printf("Special 404 pause-and-retry for GCLOUD: Pausing %s\n", backoff)
|
||
time.Sleep(backoff)
|
||
backoff404 = true
|
||
return true // Request a retry.
|
||
}
|
||
backoff404 = false
|
||
|
||
if serr.Code == 502 {
|
||
// serr.Code == 502 happens occasionally when "The server
|
||
// encountered a temporary error and could not complete your
|
||
// request. Please try again in 30 seconds. That’s all we know."
|
||
// We pause and retry exactly once.
|
||
if backoff502 {
|
||
backoff502 = false
|
||
return false // Give up. We've done this already.
|
||
}
|
||
log.Printf("Special 502 pause-and-retry for GCLOUD: Pausing %s\n", backoff)
|
||
time.Sleep(31 * time.Second)
|
||
backoff502 = true
|
||
return true // Request a retry.
|
||
}
|
||
backoff502 = false
|
||
|
||
if serr.Code != 429 && serr.Code != 503 {
|
||
return false // Not an error that permits retrying.
|
||
}
|
||
|
||
// TODO(tlim): In theory, resp.Header has a header that says how
|
||
// long to wait but I haven't been able to capture that header in
|
||
// the wild. If you get these "RUNCHANGE HEAD" messages, please
|
||
// file a bug with the contents!
|
||
|
||
if resp != nil {
|
||
log.Printf("NOTE: If you see this message, please file a bug with the output below:\n")
|
||
log.Printf("RUNCHANGE CODE = %+v\n", resp.HTTPStatusCode)
|
||
log.Printf("RUNCHANGE HEAD = %+v\n", resp.Header)
|
||
}
|
||
|
||
// a simple exponential back-off
|
||
log.Printf("Pausing due to ratelimit: %v seconds\n", backoff)
|
||
time.Sleep(backoff)
|
||
backoff = backoff + (backoff / 2)
|
||
if backoff > maxBackoff {
|
||
backoff = maxBackoff
|
||
}
|
||
|
||
return true // Request the API call be re-tried.
|
||
}
|