diff --git a/acme/api/api.go b/acme/api/api.go index 06b47c4d..b4a3eeb9 100644 --- a/acme/api/api.go +++ b/acme/api/api.go @@ -2,7 +2,6 @@ package api import ( "bytes" - "context" "crypto" "encoding/json" "errors" @@ -83,8 +82,6 @@ func (a *Core) retrievablePost(uri string, content []byte, response interface{}) bo.MaxInterval = 5 * time.Second bo.MaxElapsedTime = 20 * time.Second - ctx, cancel := context.WithCancel(context.Background()) - var resp *http.Response operation := func() error { var err error @@ -96,8 +93,7 @@ func (a *Core) retrievablePost(uri string, content []byte, response interface{}) return err } - cancel() - return err + return backoff.Permanent(err) } return nil @@ -107,7 +103,7 @@ func (a *Core) retrievablePost(uri string, content []byte, response interface{}) log.Infof("retry due to: %v", err) } - err := backoff.RetryNotify(operation, backoff.WithContext(bo, ctx), notify) + err := backoff.RetryNotify(operation, bo, notify) if err != nil { return resp, err } diff --git a/go.mod b/go.mod index 24215875..f5ee7668 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/akamai/AkamaiOPEN-edgegrid-golang v1.1.0 github.com/aliyun/alibaba-cloud-sdk-go v1.61.976 github.com/aws/aws-sdk-go v1.37.27 - github.com/cenkalti/backoff/v4 v4.1.0 + github.com/cenkalti/backoff/v4 v4.1.1 github.com/cloudflare/cloudflare-go v0.14.0 github.com/cpu/goacmedns v0.1.1 github.com/dnsimple/dnsimple-go v0.63.0 diff --git a/go.sum b/go.sum index 631fae7c..c442fa2c 100644 --- a/go.sum +++ b/go.sum @@ -78,8 +78,8 @@ github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJm github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc h1:biVzkmvwrH8WK8raXaxBx6fRVTlJILwEwQGL1I/ByEI= github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= github.com/c-bata/go-prompt v0.2.5/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw= -github.com/cenkalti/backoff/v4 v4.1.0 h1:c8LkOFQTzuO0WBM/ae5HdGQuZPfPxp7lqBRwQRm4fSc= -github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= +github.com/cenkalti/backoff/v4 v4.1.1 h1:G2HAfAmvm/GcKan2oOQpBXOd2tT2G57ZnZGWa1PxPBQ= +github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= diff --git a/providers/dns/dynu/internal/client.go b/providers/dns/dynu/internal/client.go index 1f9753e4..c6e22cf4 100644 --- a/providers/dns/dynu/internal/client.go +++ b/providers/dns/dynu/internal/client.go @@ -2,7 +2,6 @@ package internal import ( "bytes" - "context" "encoding/json" "errors" "fmt" @@ -125,8 +124,6 @@ func (c Client) GetRootDomain(hostname string) (*DNSHostname, error) { func (c Client) doRetry(method, uri string, body []byte, data interface{}) error { var resp *http.Response - ctx, cancel := context.WithCancel(context.Background()) - operation := func() error { var reqBody io.Reader if len(body) > 0 { @@ -147,8 +144,7 @@ func (c Client) doRetry(method, uri string, body []byte, data interface{}) error } if err != nil { - cancel() - return fmt.Errorf("client error: %w", err) + return backoff.Permanent(fmt.Errorf("client error: %w", err)) } return nil @@ -161,7 +157,7 @@ func (c Client) doRetry(method, uri string, body []byte, data interface{}) error bo := backoff.NewExponentialBackOff() bo.InitialInterval = 1 * time.Second - err := backoff.RetryNotify(operation, backoff.WithContext(bo, ctx), notify) + err := backoff.RetryNotify(operation, bo, notify) if err != nil { return err } diff --git a/providers/dns/hostingde/client.go b/providers/dns/hostingde/client.go index 04ed2d4e..9af1b0ac 100644 --- a/providers/dns/hostingde/client.go +++ b/providers/dns/hostingde/client.go @@ -2,7 +2,6 @@ package hostingde import ( "bytes" - "context" "encoding/json" "errors" "fmt" @@ -57,15 +56,12 @@ func (d *DNSProvider) updateZone(updateRequest ZoneUpdateRequest) (*ZoneUpdateRe } func (d *DNSProvider) getZone(findRequest ZoneConfigsFindRequest) (*ZoneConfig, error) { - ctx, cancel := context.WithCancel(context.Background()) - var zoneConfig *ZoneConfig operation := func() error { findResponse, err := d.listZoneConfigs(findRequest) if err != nil { - cancel() - return err + return backoff.Permanent(err) } if findResponse.Response.Data[0].Status != "active" { @@ -83,7 +79,7 @@ func (d *DNSProvider) getZone(findRequest ZoneConfigsFindRequest) (*ZoneConfig, bo.MaxElapsedTime = 100 * bo.InitialInterval // retry in case the zone was edited recently and is not yet active - err := backoff.Retry(operation, backoff.WithContext(bo, ctx)) + err := backoff.Retry(operation, bo) if err != nil { return nil, err }