Skip to content

Commit

Permalink
Remove deprecated code and revert to old interface
Browse files Browse the repository at this point in the history
  • Loading branch information
nicmue committed Apr 15, 2020
1 parent 62f8327 commit dac7e7c
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions http/transport/retry_round_tripper.go
Expand Up @@ -12,8 +12,8 @@ import (

// RetryRoundTripper implements a chainable round tripper for retrying requests
type RetryRoundTripper struct {
retryTransportFactory func() *retry.Transport
transport http.RoundTripper
retryTransport *retry.Transport
transport http.RoundTripper
}

// RetryCodes retries when the status code is one of the provided list
Expand Down Expand Up @@ -44,22 +44,6 @@ func Context() retry.Retryer {
}
}

// DefaultRetryTransport is used as default retry mechanism
//
// Deprecated: Use NewDefaultRetryTransport() instead. The DefaultRetryTransport
// will be removed in future versions. It is broken as its global nature means
// that the DefaultRetryTransport.Next http.RoundTripper is shared among all
// users. In previous versions of this package this would mean that the last
// user to call RetryRoundTripper.SetTransport() defines the shared
// DefaultRetryTransport.Next http.RoundTripper. This was unknowingly changed in
// v0.1.12. After that this still is at least a race condition issue as we can
// have multiple simultaneous usages, that all set DefaultRetryTransport.Next
// and indirectly call this shared state via DefaultRetryTransport.RoundTrip().
var DefaultRetryTransport = retry.Transport{
Delay: retry.Constant(100 * time.Millisecond),
Retry: retry.All(Context(), retry.Max(9), retry.EOF(), retry.Net(), retry.Temporary(), RetryCodes(408, 502, 503, 504)),
}

// NewDefaultRetryTransport returns a new default retry transport.
func NewDefaultRetryTransport() *retry.Transport {
return &retry.Transport{
Expand All @@ -69,14 +53,14 @@ func NewDefaultRetryTransport() *retry.Transport {
}

// NewRetryRoundTripper returns a retry round tripper with the specified retry transport.
func NewRetryRoundTripper(rtf func() *retry.Transport) *RetryRoundTripper {
return &RetryRoundTripper{retryTransportFactory: rtf}
func NewRetryRoundTripper(rt *retry.Transport) *RetryRoundTripper {
return &RetryRoundTripper{retryTransport: rt}
}

// NewDefaultRetryRoundTripper returns a retry round tripper with a
// NewDefaultRetryTransport() as transport.
func NewDefaultRetryRoundTripper() *RetryRoundTripper {
return &RetryRoundTripper{retryTransportFactory: func() *retry.Transport { return NewDefaultRetryTransport() }}
return &RetryRoundTripper{retryTransport: NewDefaultRetryTransport()}
}

// Transport returns the RoundTripper to make HTTP requests
Expand All @@ -91,7 +75,10 @@ func (l *RetryRoundTripper) SetTransport(rt http.RoundTripper) {

// RoundTrip executes a HTTP request with retrying
func (l *RetryRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
retryTransport := l.retryTransportFactory()
retryTransport := &retry.Transport{
Delay: l.retryTransport.Delay,
Retry: l.retryTransport.Retry,
}
retryTransport.Next = transportWithAttempt(l.Transport())
resp, err := retryTransport.RoundTrip(req)

Expand Down

0 comments on commit dac7e7c

Please sign in to comment.