mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 01:44:41 +01:00
Retry if a timeout occurs.
This happens more rarely than 500, but can still be encountered.
This commit is contained in:
parent
fa0b364f3d
commit
a23464dfa1
@ -15,7 +15,9 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
@ -126,8 +128,7 @@ func parsePath(path string) (root string) {
|
||||
// shouldRetry returns a boolean as to whether this resp and err
|
||||
// deserve to be retried. It returns the err as a convenience
|
||||
func shouldRetry(resp *http.Response, err error) (bool, error) {
|
||||
// FIXME retry other http codes?
|
||||
// 409 conflict ?
|
||||
// Retry on 429 Rate exceeded.
|
||||
if err != nil && resp != nil && resp.StatusCode == 429 {
|
||||
return true, err
|
||||
}
|
||||
@ -135,6 +136,18 @@ func shouldRetry(resp *http.Response, err error) (bool, error) {
|
||||
if err != nil && resp != nil && resp.StatusCode == 500 {
|
||||
return true, err
|
||||
}
|
||||
// Allow retry if request times out. Adapted from
|
||||
// http://stackoverflow.com/questions/23494950/specifically-check-for-timeout-error
|
||||
switch err := err.(type) {
|
||||
case *url.Error:
|
||||
if err, ok := err.Err.(net.Error); ok && err.Timeout() {
|
||||
return true, err
|
||||
}
|
||||
case net.Error:
|
||||
if err.Timeout() {
|
||||
return true, err
|
||||
}
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user