providers: remove TreatAuthAsTransient, which changed only an error's text (#8299)
release / go (push) Successful in 1m48s
release / web (push) Successful in 1m19s
release / integration (push) Successful in 2m38s
release / govulncheck (push) Successful in 20s
release / android (push) Successful in 4m29s
release / Build signed APK (push) Successful in 4m57s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Publish the release image to GHCR (dispatch only) (push) Skipped
release / Build + push container image (push) Successful in 14s
release / Verify release artifacts (tag releases only) (push) Skipped
release / go (push) Successful in 1m48s
release / web (push) Successful in 1m19s
release / integration (push) Successful in 2m38s
release / govulncheck (push) Successful in 20s
release / android (push) Successful in 4m29s
release / Build signed APK (push) Successful in 4m57s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Publish the release image to GHCR (dispatch only) (push) Skipped
release / Build + push container image (push) Successful in 14s
release / Verify release artifacts (tag releases only) (push) Skipped
Without the option a 401 or 403 already fell to the default branch, which answers ErrTransient without a retry, the same as the option's own branch. The only difference was "(auth)" in the message. TheAudioDB and both Last.fm providers set it; none read the message. The reason it gave, that a bad key retries later instead of settling the row as "none", now sits on the default branch, and the client's status table checks 401 and 403. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -46,11 +46,10 @@ type lastfmProvider struct {
|
|||||||
func init() {
|
func init() {
|
||||||
Register(&lastfmProvider{
|
Register(&lastfmProvider{
|
||||||
client: providers.NewHTTPClient(providers.HTTPOptions{
|
client: providers.NewHTTPClient(providers.HTTPOptions{
|
||||||
Name: "lastfm",
|
Name: "lastfm",
|
||||||
HTTPClient: &http.Client{Timeout: 30 * time.Second},
|
HTTPClient: &http.Client{Timeout: 30 * time.Second},
|
||||||
Pacer: providers.LastfmPacer,
|
Pacer: providers.LastfmPacer,
|
||||||
MaxRetries: lastfmMaxRetries,
|
MaxRetries: lastfmMaxRetries,
|
||||||
TreatAuthAsTransient: true,
|
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ func newLastfmTestProvider(t *testing.T, baseURL, key string) *lastfmProvider {
|
|||||||
lastfmBaseURL = baseURL
|
lastfmBaseURL = baseURL
|
||||||
t.Cleanup(func() { lastfmBaseURL = prevBase })
|
t.Cleanup(func() { lastfmBaseURL = prevBase })
|
||||||
|
|
||||||
p := &lastfmProvider{client: providers.NewHTTPClient(providers.HTTPOptions{Name: "lastfm", HTTPClient: &http.Client{Timeout: 5 * time.Second}, TreatAuthAsTransient: true, BaseBackoff: time.Millisecond})}
|
p := &lastfmProvider{client: providers.NewHTTPClient(providers.HTTPOptions{Name: "lastfm", HTTPClient: &http.Client{Timeout: 5 * time.Second}, BaseBackoff: time.Millisecond})}
|
||||||
p.enabled.Store(true)
|
p.enabled.Store(true)
|
||||||
p.apiKey.Store(&key)
|
p.apiKey.Store(&key)
|
||||||
return p
|
return p
|
||||||
@@ -152,7 +152,7 @@ func TestLastfm_FetchArtistArt_ErrorResponse(t *testing.T) {
|
|||||||
func TestLastfm_AnswersNotFoundWithoutAsking(t *testing.T) {
|
func TestLastfm_AnswersNotFoundWithoutAsking(t *testing.T) {
|
||||||
provider := func(enabled bool, key string) *lastfmProvider {
|
provider := func(enabled bool, key string) *lastfmProvider {
|
||||||
p := &lastfmProvider{client: providers.NewHTTPClient(providers.HTTPOptions{Name: "lastfm",
|
p := &lastfmProvider{client: providers.NewHTTPClient(providers.HTTPOptions{Name: "lastfm",
|
||||||
HTTPClient: &http.Client{Timeout: 5 * time.Second}, TreatAuthAsTransient: true, BaseBackoff: time.Millisecond})}
|
HTTPClient: &http.Client{Timeout: 5 * time.Second}, BaseBackoff: time.Millisecond})}
|
||||||
p.enabled.Store(enabled)
|
p.enabled.Store(enabled)
|
||||||
p.apiKey.Store(&key)
|
p.apiKey.Store(&key)
|
||||||
return p
|
return p
|
||||||
@@ -262,7 +262,7 @@ func TestLastfm_FetchAlbumCover_WithMBIDHint(t *testing.T) {
|
|||||||
// ── FetchAlbumCover — missing fields ─────────────────────────────────────────
|
// ── FetchAlbumCover — missing fields ─────────────────────────────────────────
|
||||||
|
|
||||||
func TestLastfm_FetchAlbumCover_MissingFields(t *testing.T) {
|
func TestLastfm_FetchAlbumCover_MissingFields(t *testing.T) {
|
||||||
p := &lastfmProvider{client: providers.NewHTTPClient(providers.HTTPOptions{Name: "lastfm", HTTPClient: &http.Client{Timeout: 5 * time.Second}, TreatAuthAsTransient: true, BaseBackoff: time.Millisecond})}
|
p := &lastfmProvider{client: providers.NewHTTPClient(providers.HTTPOptions{Name: "lastfm", HTTPClient: &http.Client{Timeout: 5 * time.Second}, BaseBackoff: time.Millisecond})}
|
||||||
p.enabled.Store(true)
|
p.enabled.Store(true)
|
||||||
key := "test-key"
|
key := "test-key"
|
||||||
p.apiKey.Store(&key)
|
p.apiKey.Store(&key)
|
||||||
@@ -301,11 +301,10 @@ func TestLastfm_RateLimit_Serializes(t *testing.T) {
|
|||||||
// verify the pacing actually serializes. Other tests use
|
// verify the pacing actually serializes. Other tests use
|
||||||
// newLastfmTestProvider, which doesn't pace, for speed.
|
// newLastfmTestProvider, which doesn't pace, for speed.
|
||||||
p := &lastfmProvider{client: providers.NewHTTPClient(providers.HTTPOptions{
|
p := &lastfmProvider{client: providers.NewHTTPClient(providers.HTTPOptions{
|
||||||
Name: "lastfm",
|
Name: "lastfm",
|
||||||
HTTPClient: &http.Client{Timeout: 5 * time.Second},
|
HTTPClient: &http.Client{Timeout: 5 * time.Second},
|
||||||
Pacer: providers.NewInterval(lastfmTestPeriod),
|
Pacer: providers.NewInterval(lastfmTestPeriod),
|
||||||
TreatAuthAsTransient: true,
|
BaseBackoff: time.Millisecond,
|
||||||
BaseBackoff: time.Millisecond,
|
|
||||||
})}
|
})}
|
||||||
p.enabled.Store(true)
|
p.enabled.Store(true)
|
||||||
key := "test-key"
|
key := "test-key"
|
||||||
|
|||||||
@@ -51,11 +51,10 @@ type theAudioDBProvider struct {
|
|||||||
func init() {
|
func init() {
|
||||||
Register(&theAudioDBProvider{
|
Register(&theAudioDBProvider{
|
||||||
client: providers.NewHTTPClient(providers.HTTPOptions{
|
client: providers.NewHTTPClient(providers.HTTPOptions{
|
||||||
Name: "theaudiodb",
|
Name: "theaudiodb",
|
||||||
HTTPClient: &http.Client{Timeout: 30 * time.Second},
|
HTTPClient: &http.Client{Timeout: 30 * time.Second},
|
||||||
MinInterval: theAudioDBMinPeriod,
|
MinInterval: theAudioDBMinPeriod,
|
||||||
MaxRetries: theAudioDBMaxRetries,
|
MaxRetries: theAudioDBMaxRetries,
|
||||||
TreatAuthAsTransient: true,
|
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func newTheAudioDBProviderForTest(t *testing.T, mockURL string) *theAudioDBProvi
|
|||||||
withTheAudioDBBaseURL(t, mockURL)
|
withTheAudioDBBaseURL(t, mockURL)
|
||||||
|
|
||||||
p := &theAudioDBProvider{
|
p := &theAudioDBProvider{
|
||||||
client: providers.NewHTTPClient(providers.HTTPOptions{Name: "theaudiodb", HTTPClient: &http.Client{Timeout: 5 * time.Second}, TreatAuthAsTransient: true, BaseBackoff: time.Millisecond}),
|
client: providers.NewHTTPClient(providers.HTTPOptions{Name: "theaudiodb", HTTPClient: &http.Client{Timeout: 5 * time.Second}, BaseBackoff: time.Millisecond}),
|
||||||
}
|
}
|
||||||
Register(p)
|
Register(p)
|
||||||
p.enabled.Store(true)
|
p.enabled.Store(true)
|
||||||
@@ -221,7 +221,7 @@ func TestTheAudioDB_DefaultsToTestKeyOnEmpty(t *testing.T) {
|
|||||||
defer resetRegistryForTests()
|
defer resetRegistryForTests()
|
||||||
withTheAudioDBBaseURL(t, srv.URL)
|
withTheAudioDBBaseURL(t, srv.URL)
|
||||||
|
|
||||||
p := &theAudioDBProvider{client: providers.NewHTTPClient(providers.HTTPOptions{Name: "theaudiodb", HTTPClient: &http.Client{Timeout: 5 * time.Second}, TreatAuthAsTransient: true, BaseBackoff: time.Millisecond})}
|
p := &theAudioDBProvider{client: providers.NewHTTPClient(providers.HTTPOptions{Name: "theaudiodb", HTTPClient: &http.Client{Timeout: 5 * time.Second}, BaseBackoff: time.Millisecond})}
|
||||||
Register(p)
|
Register(p)
|
||||||
// Configure with empty key — should fall back to test key.
|
// Configure with empty key — should fall back to test key.
|
||||||
if err := p.Configure(ProviderSettings{Enabled: true, APIKey: ""}); err != nil {
|
if err := p.Configure(ProviderSettings{Enabled: true, APIKey: ""}); err != nil {
|
||||||
|
|||||||
@@ -45,10 +45,6 @@ type HTTPOptions struct {
|
|||||||
MaxRetries int
|
MaxRetries int
|
||||||
// BaseBackoff is the backoff unit: 2^attempt × base ± 20%.
|
// BaseBackoff is the backoff unit: 2^attempt × base ± 20%.
|
||||||
BaseBackoff time.Duration
|
BaseBackoff time.Duration
|
||||||
// TreatAuthAsTransient maps 401/403 to ErrTransient, so a bad or
|
|
||||||
// expired key retries later rather than settling the row as "none".
|
|
||||||
// Keyed providers want this.
|
|
||||||
TreatAuthAsTransient bool
|
|
||||||
// JSONBodyLimit and ImageBodyLimit cap a response body, against a
|
// JSONBodyLimit and ImageBodyLimit cap a response body, against a
|
||||||
// runaway upstream.
|
// runaway upstream.
|
||||||
JSONBodyLimit int64
|
JSONBodyLimit int64
|
||||||
@@ -191,10 +187,6 @@ func (c *HTTPClient) attempt(ctx context.Context, fullURL, accept string, attemp
|
|||||||
case resp.StatusCode == http.StatusNotFound:
|
case resp.StatusCode == http.StatusNotFound:
|
||||||
_ = resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
return nil, false, ErrNotFound
|
return nil, false, ErrNotFound
|
||||||
case c.opts.TreatAuthAsTransient &&
|
|
||||||
(resp.StatusCode == http.StatusUnauthorized || resp.StatusCode == http.StatusForbidden):
|
|
||||||
_ = resp.Body.Close()
|
|
||||||
return nil, false, fmt.Errorf("%w: status %d (auth)", ErrTransient, resp.StatusCode)
|
|
||||||
case resp.StatusCode == http.StatusTooManyRequests || resp.StatusCode >= 500:
|
case resp.StatusCode == http.StatusTooManyRequests || resp.StatusCode >= 500:
|
||||||
_ = resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
if attempt < c.opts.MaxRetries {
|
if attempt < c.opts.MaxRetries {
|
||||||
@@ -205,6 +197,9 @@ func (c *HTTPClient) attempt(ctx context.Context, fullURL, accept string, attemp
|
|||||||
}
|
}
|
||||||
return nil, false, fmt.Errorf("%w: status %d", ErrTransient, resp.StatusCode)
|
return nil, false, fmt.Errorf("%w: status %d", ErrTransient, resp.StatusCode)
|
||||||
default:
|
default:
|
||||||
|
// Any other answer, a refused key's 401 or 403 included, is
|
||||||
|
// transient: a bad or expired key is asked again later instead of
|
||||||
|
// settling the row as having nothing to find.
|
||||||
_ = resp.Body.Close()
|
_ = resp.Body.Close()
|
||||||
return nil, false, fmt.Errorf("%w: status %d", ErrTransient, resp.StatusCode)
|
return nil, false, fmt.Errorf("%w: status %d", ErrTransient, resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,26 +29,25 @@ func TestHTTPClient_GetJSON_Success(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A 404 settles the lookup as not found; any other failure, including a
|
// A 404 settles the lookup as not found; any other failure, including a
|
||||||
// refused key and a body that isn't JSON, is transient and asked again later.
|
// refused key and a body that isn't JSON, is transient and asked again later,
|
||||||
// A 401 is transient with or without TreatAuthAsTransient.
|
// so a bad or expired key never settles a row as having no picture.
|
||||||
func TestHTTPClient_GetJSON_AnswersNotFoundOrTransient(t *testing.T) {
|
func TestHTTPClient_GetJSON_AnswersNotFoundOrTransient(t *testing.T) {
|
||||||
for _, tc := range []struct {
|
for _, tc := range []struct {
|
||||||
name string
|
name string
|
||||||
status int
|
status int
|
||||||
body string
|
body string
|
||||||
authAsRetry bool
|
want error
|
||||||
want error
|
|
||||||
}{
|
}{
|
||||||
{"404", http.StatusNotFound, "", false, ErrNotFound},
|
{"404", http.StatusNotFound, "", ErrNotFound},
|
||||||
{"401", http.StatusUnauthorized, "", false, ErrTransient},
|
{"401", http.StatusUnauthorized, "", ErrTransient},
|
||||||
{"401 with TreatAuthAsTransient", http.StatusUnauthorized, "", true, ErrTransient},
|
{"403", http.StatusForbidden, "", ErrTransient},
|
||||||
{"a body that isn't JSON", http.StatusOK, "not json", false, ErrTransient},
|
{"a body that isn't JSON", http.StatusOK, "not json", ErrTransient},
|
||||||
} {
|
} {
|
||||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||||
w.WriteHeader(tc.status)
|
w.WriteHeader(tc.status)
|
||||||
_, _ = w.Write([]byte(tc.body))
|
_, _ = w.Write([]byte(tc.body))
|
||||||
}))
|
}))
|
||||||
c := NewHTTPClient(HTTPOptions{Name: "test", TreatAuthAsTransient: tc.authAsRetry})
|
c := NewHTTPClient(HTTPOptions{Name: "test"})
|
||||||
var out struct{ Name string }
|
var out struct{ Name string }
|
||||||
err := c.GetJSON(context.Background(), srv.URL, &out)
|
err := c.GetJSON(context.Background(), srv.URL, &out)
|
||||||
srv.Close()
|
srv.Close()
|
||||||
|
|||||||
@@ -32,11 +32,10 @@ type lastfmProvider struct {
|
|||||||
func init() {
|
func init() {
|
||||||
Register(&lastfmProvider{
|
Register(&lastfmProvider{
|
||||||
client: providers.NewHTTPClient(providers.HTTPOptions{
|
client: providers.NewHTTPClient(providers.HTTPOptions{
|
||||||
Name: "lastfm",
|
Name: "lastfm",
|
||||||
HTTPClient: &http.Client{Timeout: 30 * time.Second},
|
HTTPClient: &http.Client{Timeout: 30 * time.Second},
|
||||||
Pacer: providers.LastfmPacer,
|
Pacer: providers.LastfmPacer,
|
||||||
MaxRetries: 3,
|
MaxRetries: 3,
|
||||||
TreatAuthAsTransient: true,
|
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
func newLastfmProvider(enabled bool, key string) *lastfmProvider {
|
func newLastfmProvider(enabled bool, key string) *lastfmProvider {
|
||||||
p := &lastfmProvider{client: providers.NewHTTPClient(providers.HTTPOptions{
|
p := &lastfmProvider{client: providers.NewHTTPClient(providers.HTTPOptions{
|
||||||
Name: "lastfm", MaxRetries: 1, TreatAuthAsTransient: true,
|
Name: "lastfm", MaxRetries: 1,
|
||||||
})}
|
})}
|
||||||
_ = p.Configure(ProviderSettings{Enabled: enabled, APIKey: key})
|
_ = p.Configure(ProviderSettings{Enabled: enabled, APIKey: key})
|
||||||
return p
|
return p
|
||||||
|
|||||||
Reference in New Issue
Block a user