fix: network failure err check should ignore context canceled errors (#10567)

context canceled errors bubbling up from the network
layer has the potential to be misconstrued as network
errors, taking prematurely a server offline and triggering
a health check routine avoid this potential occurrence.
master
Harshavardhana 4 years ago committed by GitHub
parent 9603489dd3
commit 66b4a862e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      cmd/rest/client.go
  2. 4
      pkg/net/url.go

@ -112,7 +112,7 @@ func (c *Client) Call(ctx context.Context, method string, values url.Values, bod
} }
resp, err := c.httpClient.Do(req) resp, err := c.httpClient.Do(req)
if err != nil { if err != nil {
if xnet.IsNetworkOrHostDown(err) || errors.Is(err, context.DeadlineExceeded) { if xnet.IsNetworkOrHostDown(err) {
c.MarkOffline() c.MarkOffline()
} }
return nil, &NetworkError{err} return nil, &NetworkError{err}
@ -141,6 +141,9 @@ func (c *Client) Call(ctx context.Context, method string, values url.Values, bod
// Limit the ReadAll(), just in case, because of a bug, the server responds with large data. // Limit the ReadAll(), just in case, because of a bug, the server responds with large data.
b, err := ioutil.ReadAll(io.LimitReader(resp.Body, c.MaxErrResponseSize)) b, err := ioutil.ReadAll(io.LimitReader(resp.Body, c.MaxErrResponseSize))
if err != nil { if err != nil {
if xnet.IsNetworkOrHostDown(err) {
c.MarkOffline()
}
return nil, err return nil, err
} }
if len(b) > 0 { if len(b) > 0 {

@ -17,6 +17,7 @@
package net package net
import ( import (
"context"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
@ -144,6 +145,9 @@ func IsNetworkOrHostDown(err error) bool {
if err == nil { if err == nil {
return false return false
} }
if errors.Is(err, context.Canceled) {
return false
}
// We need to figure if the error either a timeout // We need to figure if the error either a timeout
// or a non-temporary error. // or a non-temporary error.
e, ok := err.(net.Error) e, ok := err.(net.Error)

Loading…
Cancel
Save