|
|
@ -29,7 +29,6 @@ import ( |
|
|
|
"io/ioutil" |
|
|
|
"io/ioutil" |
|
|
|
"net" |
|
|
|
"net" |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"net/url" |
|
|
|
|
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"path/filepath" |
|
|
|
"path/filepath" |
|
|
|
"reflect" |
|
|
|
"reflect" |
|
|
@ -426,43 +425,6 @@ func newContext(r *http.Request, w http.ResponseWriter, api string) context.Cont |
|
|
|
return logger.SetReqInfo(r.Context(), reqInfo) |
|
|
|
return logger.SetReqInfo(r.Context(), reqInfo) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// isNetworkOrHostDown - if there was a network error or if the host is down.
|
|
|
|
|
|
|
|
func isNetworkOrHostDown(err error) bool { |
|
|
|
|
|
|
|
if err == nil { |
|
|
|
|
|
|
|
return false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// We need to figure if the error either a timeout
|
|
|
|
|
|
|
|
// or a non-temporary error.
|
|
|
|
|
|
|
|
e, ok := err.(net.Error) |
|
|
|
|
|
|
|
if ok { |
|
|
|
|
|
|
|
urlErr, ok := e.(*url.Error) |
|
|
|
|
|
|
|
if ok { |
|
|
|
|
|
|
|
switch urlErr.Err.(type) { |
|
|
|
|
|
|
|
case *net.DNSError, *net.OpError, net.UnknownNetworkError: |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if e.Timeout() { |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ok = false |
|
|
|
|
|
|
|
// Fallback to other mechanisms.
|
|
|
|
|
|
|
|
if strings.Contains(err.Error(), "Connection closed by foreign host") { |
|
|
|
|
|
|
|
ok = true |
|
|
|
|
|
|
|
} else if strings.Contains(err.Error(), "TLS handshake timeout") { |
|
|
|
|
|
|
|
// If error is - tlsHandshakeTimeoutError.
|
|
|
|
|
|
|
|
ok = true |
|
|
|
|
|
|
|
} else if strings.Contains(err.Error(), "i/o timeout") { |
|
|
|
|
|
|
|
// If error is - tcp timeoutError.
|
|
|
|
|
|
|
|
ok = true |
|
|
|
|
|
|
|
} else if strings.Contains(err.Error(), "connection timed out") { |
|
|
|
|
|
|
|
// If err is a net.Dial timeout.
|
|
|
|
|
|
|
|
ok = true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return ok |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Used for registering with rest handlers (have a look at registerStorageRESTHandlers for usage example)
|
|
|
|
// Used for registering with rest handlers (have a look at registerStorageRESTHandlers for usage example)
|
|
|
|
// If it is passed ["aaaa", "bbbb"], it returns ["aaaa", "{aaaa:.*}", "bbbb", "{bbbb:.*}"]
|
|
|
|
// If it is passed ["aaaa", "bbbb"], it returns ["aaaa", "{aaaa:.*}", "bbbb", "{bbbb:.*}"]
|
|
|
|
func restQueries(keys ...string) []string { |
|
|
|
func restQueries(keys ...string) []string { |
|
|
|