From a80e852aab63f4461b5203678a3fe04b4a694a47 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 23 Jun 2020 12:25:02 +0300 Subject: [PATCH] lib/promscrape: retry performing the request to the server for up to 3 times before giving up when it closes keep-alive connections Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/580 --- lib/promscrape/client.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/promscrape/client.go b/lib/promscrape/client.go index b52d227eb..f4e28936b 100644 --- a/lib/promscrape/client.go +++ b/lib/promscrape/client.go @@ -133,6 +133,8 @@ var ( ) func doRequestWithPossibleRetry(hc *fasthttp.HostClient, req *fasthttp.Request, resp *fasthttp.Response) error { + attempts := 0 +again: // There is no need in calling DoTimeout, since the timeout must be already set in hc.ReadTimeout. err := hc.Do(req, resp) if err == nil { @@ -142,5 +144,9 @@ func doRequestWithPossibleRetry(hc *fasthttp.HostClient, req *fasthttp.Request, return err } // Retry request if the server closed the keep-alive connection during the first attempt. - return hc.Do(req, resp) + attempts++ + if attempts > 3 { + return fmt.Errorf("the server closed 3 subsequent connections: %s", err) + } + goto again }