Retry if a timeout occurs.
This happens more rarely than 500, but can still be encountered.
This commit is contained in:
parent
6ac7145d2d
commit
fa87077211
1 changed files with 15 additions and 2 deletions
|
@ -15,7 +15,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -124,8 +126,7 @@ func parsePath(path string) (root string) {
|
||||||
// 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) {
|
||||||
// FIXME retry other http codes?
|
// Retry on 429 Rate exceeded.
|
||||||
// 409 conflict ?
|
|
||||||
if err != nil && resp != nil && resp.StatusCode == 429 {
|
if err != nil && resp != nil && resp.StatusCode == 429 {
|
||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
|
@ -133,6 +134,18 @@ func shouldRetry(resp *http.Response, err error) (bool, error) {
|
||||||
if err != nil && resp != nil && resp.StatusCode == 500 {
|
if err != nil && resp != nil && resp.StatusCode == 500 {
|
||||||
return true, err
|
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
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue