lib/promscrape/discoveryutils: properly check for net.ErrClosed (#4426)

This error may be wrapped in another error, and should normally be tested using
`errors.Is(err, net.ErrClosed)`.

Signed-off-by: hagen1778 <roman@victoriametrics.com>
(cherry picked from commit dfe53a36fc)
This commit is contained in:
Roman Khavronenko 2023-06-09 09:26:33 +02:00 committed by hagen1778
parent c42365dc31
commit d677c2a5a6
No known key found for this signature in database
GPG key ID: 3BF75F3741CA9640

View file

@ -3,6 +3,7 @@ package discoveryutils
import (
"context"
"crypto/tls"
"errors"
"flag"
"fmt"
"io"
@ -301,7 +302,7 @@ func doRequestWithPossibleRetry(hc *HTTPClient, req *http.Request) (*http.Respon
if statusCode != http.StatusTooManyRequests {
return true
}
} else if reqErr != net.ErrClosed && !strings.Contains(reqErr.Error(), "broken pipe") {
} else if !errors.Is(reqErr, net.ErrClosed) && !strings.Contains(reqErr.Error(), "broken pipe") {
return true
}
return false