Skip to content

Commit

Permalink
registry unavailable error for 5XX status code.
Browse files Browse the repository at this point in the history
Of course after exhausing all retries.
  • Loading branch information
hchienjo committed Mar 4, 2024
1 parent 5753d28 commit cd4a426
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 11 additions & 7 deletions avroregistry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,23 @@ func (r *Registry) doRequest(req *http.Request, result interface{}) error {
if err == nil {
return nil
}
if !attempt.More() {
return &UnavailableError{err}
}
if err, ok := err.(*apiError); ok && err.StatusCode != http.StatusInternalServerError {
// It's not a 5xx error. We want to retry on 5xx
if err, ok := err.(*apiError); ok {
// We want to retry on 5xx
// errors, because the Confluent Avro registry
// can occasionally return them as a matter of
// course (and there could also be an
// unavailable service that we're reaching
// through a proxy).
if !attempt.More() {
return &UnavailableError{err}
switch err.StatusCode {
case http.StatusInternalServerError:
if !attempt.More() {
return &UnavailableError{err}
}
default:
return err
}
}
if !attempt.More() {
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions avroregistry/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func TestRetryOn500(t *testing.T) {
// an error.
failCount = 5
err = registry.SetCompatibility(context.Background(), "x", avro.BackwardTransitive)
c.Assert(err, qt.ErrorMatches, `Avro registry error \(code 50001; HTTP status 500\): Failed to update compatibility level`)
c.Assert(err, qt.ErrorMatches, `schema registry unavailability caused by: Avro registry error \(code 50001; HTTP status 500\): Failed to update compatibility level`)
}

func TestNoRetryOnNon5XXStatus(t *testing.T) {
Expand Down Expand Up @@ -392,7 +392,7 @@ func TestUnavailableError(t *testing.T) {
})
c.Assert(err, qt.Equals, nil)
err = registry.SetCompatibility(context.Background(), "x", avro.BackwardTransitive)
c.Assert(err, qt.ErrorMatches, `cannot unmarshal JSON error response from .*/config/x: unexpected content type text/html; want application/json; content: 502 Proxy Error; Proxy Error; The whole world is bogus`)
c.Assert(err, qt.ErrorMatches, `schema registry unavailability caused by: cannot unmarshal JSON error response from .*/config/x: unexpected content type text/html; want application/json; content: 502 Proxy Error; Proxy Error; The whole world is bogus`)
}

var schemaEquivalenceTests = []struct {
Expand Down

0 comments on commit cd4a426

Please sign in to comment.