8 "github.com/aws/aws-sdk-go/aws/request"
11 // DefaultRetryer implements basic retry logic using exponential backoff for
12 // most services. If you want to implement custom retry logic, implement the
13 // request.Retryer interface or create a structure type that composes this
14 // struct and override the specific methods. For example, to override only
15 // the MaxRetries method:
17 // type retryer struct {
18 // service.DefaultRetryer
21 // // This implementation always has 100 max retries
22 // func (d retryer) MaxRetries() uint { return 100 }
23 type DefaultRetryer struct {
27 // MaxRetries returns the number of maximum returns the service will use to make
28 // an individual API request.
29 func (d DefaultRetryer) MaxRetries() int {
30 return d.NumMaxRetries
33 var seededRand = rand.New(&lockedSource{src: rand.NewSource(time.Now().UnixNano())})
35 // RetryRules returns the delay duration before retrying this request again
36 func (d DefaultRetryer) RetryRules(r *request.Request) time.Duration {
37 // Set the upper limit of delay in retrying at ~five minutes
39 throttle := d.shouldThrottle(r)
44 retryCount := r.RetryCount
47 } else if throttle && retryCount > 8 {
51 delay := (1 << uint(retryCount)) * (seededRand.Intn(minTime) + minTime)
52 return time.Duration(delay) * time.Millisecond
55 // ShouldRetry returns true if the request should be retried.
56 func (d DefaultRetryer) ShouldRetry(r *request.Request) bool {
57 // If one of the other handlers already set the retry state
58 // we don't want to override it based on the service's state
59 if r.Retryable != nil {
63 if r.HTTPResponse.StatusCode >= 500 {
66 return r.IsErrorRetryable() || d.shouldThrottle(r)
69 // ShouldThrottle returns true if the request should be throttled.
70 func (d DefaultRetryer) shouldThrottle(r *request.Request) bool {
71 if r.HTTPResponse.StatusCode == 502 ||
72 r.HTTPResponse.StatusCode == 503 ||
73 r.HTTPResponse.StatusCode == 504 {
76 return r.IsErrorThrottle()
79 // lockedSource is a thread-safe implementation of rand.Source
80 type lockedSource struct {
85 func (r *lockedSource) Int63() (n int64) {
92 func (r *lockedSource) Seed(seed int64) {