forked from TrueCloudLab/rclone
amazon cloud drive: retry 409 errors too
This commit is contained in:
parent
f50f353b5d
commit
235cbe0e57
1 changed files with 16 additions and 8 deletions
|
@ -20,6 +20,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ncw/go-acd"
|
"github.com/ncw/go-acd"
|
||||||
|
@ -28,7 +29,6 @@ import (
|
||||||
"github.com/ncw/rclone/oauthutil"
|
"github.com/ncw/rclone/oauthutil"
|
||||||
"github.com/ncw/rclone/pacer"
|
"github.com/ncw/rclone/pacer"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -125,17 +125,25 @@ func parsePath(path string) (root string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// retryErrorCodes is a slice of error codes that we will retry
|
||||||
|
var retryErrorCodes = []int{
|
||||||
|
429, // Rate exceeded.
|
||||||
|
500, // Get occasional 500 Internal Server Error
|
||||||
|
409, // Conflict - happens in the unit tests a lot
|
||||||
|
}
|
||||||
|
|
||||||
// shouldRetry returns a boolean as to whether this resp and err
|
// shouldRetry returns a boolean as to whether this resp and err
|
||||||
// deserve to be retried. It returns the err as a convenience
|
// deserve to be retried. It returns the err as a convenience
|
||||||
func shouldRetry(resp *http.Response, err error) (bool, error) {
|
func shouldRetry(resp *http.Response, err error) (bool, error) {
|
||||||
// Retry on 429 Rate exceeded.
|
// See if HTTP error code is to be retried
|
||||||
if err != nil && resp != nil && resp.StatusCode == 429 {
|
if err != nil && resp != nil {
|
||||||
return true, err
|
for _, e := range retryErrorCodes {
|
||||||
}
|
if resp.StatusCode == e {
|
||||||
// Retry on occasional 500 Internal Server Error
|
return true, err
|
||||||
if err != nil && resp != nil && resp.StatusCode == 500 {
|
}
|
||||||
return true, err
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow retry if request times out. Adapted from
|
// Allow retry if request times out. Adapted from
|
||||||
// http://stackoverflow.com/questions/23494950/specifically-check-for-timeout-error
|
// http://stackoverflow.com/questions/23494950/specifically-check-for-timeout-error
|
||||||
switch err := err.(type) {
|
switch err := err.(type) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue