mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-30 15:22:07 +00:00
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
This commit is contained in:
parent
530f7a21e8
commit
4c7f216dfe
1 changed files with 7 additions and 1 deletions
|
@ -133,6 +133,8 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func doRequestWithPossibleRetry(hc *fasthttp.HostClient, req *fasthttp.Request, resp *fasthttp.Response) error {
|
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.
|
// There is no need in calling DoTimeout, since the timeout must be already set in hc.ReadTimeout.
|
||||||
err := hc.Do(req, resp)
|
err := hc.Do(req, resp)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -142,5 +144,9 @@ func doRequestWithPossibleRetry(hc *fasthttp.HostClient, req *fasthttp.Request,
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Retry request if the server closed the keep-alive connection during the first attempt.
|
// 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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue