vitess.io/vitess@v0.16.2/go/vt/mysqlctl/s3backupstorage/retryer.go (about)

     1  package s3backupstorage
     2  
     3  import (
     4  	"strings"
     5  	"time"
     6  
     7  	"github.com/aws/aws-sdk-go/aws/awserr"
     8  	"github.com/aws/aws-sdk-go/aws/request"
     9  )
    10  
    11  // ClosedConnectionRetryer implements the aws request.Retryer interface
    12  // and is used to retry closed connection errors during MultipartUpload
    13  // operations.
    14  type ClosedConnectionRetryer struct {
    15  	awsRetryer request.Retryer
    16  }
    17  
    18  // RetryRules is part of the Retryer interface. It defers to the underlying
    19  // aws Retryer to compute backoff rules.
    20  func (retryer *ClosedConnectionRetryer) RetryRules(r *request.Request) time.Duration {
    21  	return retryer.awsRetryer.RetryRules(r)
    22  }
    23  
    24  // ShouldRetry is part of the Retryer interface. It retries on errors that occur
    25  // due to a closed network connection, and then falls back to the underlying aws
    26  // Retryer for checking additional retry conditions.
    27  func (retryer *ClosedConnectionRetryer) ShouldRetry(r *request.Request) bool {
    28  	if retryer.MaxRetries() == 0 {
    29  		return false
    30  	}
    31  
    32  	if r.Retryable != nil {
    33  		return *r.Retryable
    34  	}
    35  
    36  	if r.Error != nil {
    37  		if awsErr, ok := r.Error.(awserr.Error); ok {
    38  			if strings.Contains(awsErr.Error(), "use of closed network connection") {
    39  				return true
    40  			}
    41  		}
    42  	}
    43  
    44  	return retryer.awsRetryer.ShouldRetry(r)
    45  }
    46  
    47  // MaxRetries is part of the Retryer interface. It defers to the
    48  // underlying aws Retryer for the max number of retries.
    49  func (retryer *ClosedConnectionRetryer) MaxRetries() int {
    50  	return retryer.awsRetryer.MaxRetries()
    51  }