Skip to content

Commit

Permalink
[registry-facade] Force retry on timeout (gitpod-io#19649)
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf authored Apr 22, 2024
1 parent 1ab8e46 commit de326c4
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions components/registry-facade/pkg/registry/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@
package registry

import (
"context"
"net/http"

"github.com/gitpod-io/gitpod/common-go/log"
"github.com/hashicorp/go-retryablehttp"
"github.com/sirupsen/logrus"
)

// Temporaryable is to match an error that has `.Temporary()`
type Temporaryable interface {
Temporary() bool
}

// Timeoutable is to match an error that has `.Timeout()`
type Timeoutable interface {
Timeout() bool
}

type Option func(opts *httpOpts)

func NewRetryableHTTPClient(options ...Option) *http.Client {
Expand All @@ -30,6 +41,18 @@ func NewRetryableHTTPClient(options ...Option) *http.Client {
client.HTTPClient = opts.HTTPClient
}

client.CheckRetry = func(ctx context.Context, resp *http.Response, err error) (bool, error) {
if terr, ok := err.(Temporaryable); ok && terr.Temporary() {
return true, nil
}

if terr, ok := err.(Timeoutable); ok && terr.Timeout() {
return true, nil
}

return retryablehttp.DefaultRetryPolicy(ctx, resp, err)
}

return client.StandardClient()
}

Expand Down

0 comments on commit de326c4

Please sign in to comment.