mirror of
https://github.com/minio/minio.git
synced 2025-11-09 21:49:46 -05:00
Unwrap network errors (#10934)
Alternative to #10927 Instead of having an upstream fix, do unwrap when checking network errors. 'As' will also work when destination is an interface as checked by the tests.
This commit is contained in:
@@ -141,7 +141,7 @@ func ParseURL(s string) (u *URL, err error) {
|
||||
}
|
||||
|
||||
// IsNetworkOrHostDown - if there was a network error or if the host is down.
|
||||
// expectTimeouts indicates that context timeouts are expected and does not
|
||||
// expectTimeouts indicates that *context* timeouts are expected and does not
|
||||
// indicate a downed host. Other timeouts still returns down.
|
||||
func IsNetworkOrHostDown(err error, expectTimeouts bool) bool {
|
||||
if err == nil {
|
||||
@@ -158,37 +158,37 @@ func IsNetworkOrHostDown(err error, expectTimeouts bool) bool {
|
||||
|
||||
// We need to figure if the error either a timeout
|
||||
// or a non-temporary error.
|
||||
e, ok := err.(net.Error)
|
||||
if ok {
|
||||
if urlErr, ok := e.(*url.Error); ok {
|
||||
switch urlErr.Err.(type) {
|
||||
case *net.DNSError, *net.OpError, net.UnknownNetworkError:
|
||||
return true
|
||||
}
|
||||
urlErr := &url.Error{}
|
||||
if errors.As(err, &urlErr) {
|
||||
switch urlErr.Err.(type) {
|
||||
case *net.DNSError, *net.OpError, net.UnknownNetworkError:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
var e net.Error
|
||||
if errors.As(err, &e) {
|
||||
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") {
|
||||
switch {
|
||||
case strings.Contains(err.Error(), "Connection closed by foreign host"):
|
||||
return true
|
||||
case strings.Contains(err.Error(), "TLS handshake timeout"):
|
||||
// If error is - tlsHandshakeTimeoutError.
|
||||
ok = true
|
||||
} else if strings.Contains(err.Error(), "i/o timeout") {
|
||||
return true
|
||||
case strings.Contains(err.Error(), "i/o timeout"):
|
||||
// If error is - tcp timeoutError.
|
||||
ok = true
|
||||
} else if strings.Contains(err.Error(), "connection timed out") {
|
||||
return true
|
||||
case strings.Contains(err.Error(), "connection timed out"):
|
||||
// If err is a net.Dial timeout.
|
||||
ok = true
|
||||
} else if strings.Contains(strings.ToLower(err.Error()), "503 service unavailable") {
|
||||
return true
|
||||
case strings.Contains(strings.ToLower(err.Error()), "503 service unavailable"):
|
||||
// Denial errors
|
||||
ok = true
|
||||
return true
|
||||
}
|
||||
return ok
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user