From 66b4a862e0bd4f0a45c6bdc8ba1589cc57d6c084 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 25 Sep 2020 14:35:47 -0700 Subject: [PATCH] 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. --- cmd/rest/client.go | 5 ++++- pkg/net/url.go | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/rest/client.go b/cmd/rest/client.go index 10602a0db..1e6a17c64 100644 --- a/cmd/rest/client.go +++ b/cmd/rest/client.go @@ -112,7 +112,7 @@ func (c *Client) Call(ctx context.Context, method string, values url.Values, bod } resp, err := c.httpClient.Do(req) if err != nil { - if xnet.IsNetworkOrHostDown(err) || errors.Is(err, context.DeadlineExceeded) { + if xnet.IsNetworkOrHostDown(err) { c.MarkOffline() } 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. b, err := ioutil.ReadAll(io.LimitReader(resp.Body, c.MaxErrResponseSize)) if err != nil { + if xnet.IsNetworkOrHostDown(err) { + c.MarkOffline() + } return nil, err } if len(b) > 0 { diff --git a/pkg/net/url.go b/pkg/net/url.go index 1979455b4..7d7e36d0c 100644 --- a/pkg/net/url.go +++ b/pkg/net/url.go @@ -17,6 +17,7 @@ package net import ( + "context" "encoding/json" "errors" "fmt" @@ -144,6 +145,9 @@ func IsNetworkOrHostDown(err error) bool { if err == nil { return false } + if errors.Is(err, context.Canceled) { + return false + } // We need to figure if the error either a timeout // or a non-temporary error. e, ok := err.(net.Error)