Skip to content

Commit

Permalink
Remove retries from HTTPReader (breaking change)
Browse files Browse the repository at this point in the history
  • Loading branch information
marselester committed Jan 30, 2024
1 parent a850ca9 commit fe45ad7
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 44 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## 7.0.0

* `HTTPReader` no longer retries on HTTP errors and therefore
`retryFor` was removed from `NewHTTPReader`.

## 6.1.0 (2024-01-09)

* `geoipupdate` now sets the version in the `User-Agent` header to the
Expand Down
42 changes: 1 addition & 41 deletions pkg/geoipupdate/database/http_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
"strconv"
"time"

"github.com/cenkalti/backoff/v4"

"github.com/maxmind/geoipupdate/v6/pkg/geoipupdate/internal"
"github.com/maxmind/geoipupdate/v6/pkg/geoipupdate/vars"
)
Expand All @@ -33,8 +31,6 @@ type HTTPReader struct {
accountID int
// licenseKey is used for request auth.
licenseKey string
// retryFor sets the timeout for when a request can no longuer be retried.
retryFor time.Duration
// verbose turns on/off debug logs.
verbose bool
}
Expand All @@ -46,7 +42,6 @@ func NewHTTPReader(
path string,
accountID int,
licenseKey string,
retryFor time.Duration,
verbose bool,
) Reader {
transport := http.DefaultTransport
Expand All @@ -60,7 +55,6 @@ func NewHTTPReader(
path: path,
accountID: accountID,
licenseKey: licenseKey,
retryFor: retryFor,
verbose: verbose,
}
}
Expand All @@ -71,41 +65,7 @@ func NewHTTPReader(
// It's the responsibility of the Writer to close the io.ReadCloser
// included in the response after consumption.
func (r *HTTPReader) Read(ctx context.Context, editionID, hash string) (*ReadResult, error) {
var result *ReadResult
var err error

if r.retryFor == 0 {
if result, err = r.get(ctx, editionID, hash); err != nil {
return nil, fmt.Errorf("getting update for %s: %w", editionID, err)
}

return result, nil
}

exp := backoff.NewExponentialBackOff()
exp.MaxElapsedTime = r.retryFor
b := backoff.BackOff(exp)

err = backoff.RetryNotify(
func() error {
result, err = r.get(ctx, editionID, hash)
if err == nil {
return nil
}

if internal.IsPermanentError(err) {
return backoff.Permanent(err)
}

return err
},
b,
func(err error, d time.Duration) {
if r.verbose {
log.Printf("Couldn't download %s, retrying in %v: %v", editionID, d, err)
}
},
)
result, err := r.get(ctx, editionID, hash)
if err != nil {
return nil, fmt.Errorf("getting update for %s: %w", editionID, err)
}
Expand Down
1 change: 0 additions & 1 deletion pkg/geoipupdate/database/http_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ func TestHTTPReader(t *testing.T) {
server.URL, // fixed, as the server is mocked above.
10, // fixed, as it's not valuable for the purpose of the test.
"license", // fixed, as it's not valuable for the purpose of the test.
0, // zero means no retries.
false, // verbose
)

Expand Down
2 changes: 0 additions & 2 deletions pkg/geoipupdate/geoip_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ func NewClient(config *Config) *Client {
config.URL,
config.AccountID,
config.LicenseKey,
// Disable retries in Reader because Client handles retries itself.
0,
config.Verbose,
), nil
}
Expand Down

0 comments on commit fe45ad7

Please sign in to comment.