app/vmagent/remotewrite: do not retry request immediately on io.ErrUnexpectedEOF, since this error isn't returned on stale connection

Also, mention the https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4139 in comments to the code
in order to simplify further maintenance of this code.

This is a follow-up for 992a1c0a3a
This commit is contained in:
Aliaksandr Valialkin 2023-08-29 09:36:03 +02:00
parent 0e31415b34
commit 9d2260ed3c
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1

View file

@ -325,10 +325,11 @@ func (c *client) runWorker() {
func (c *client) doRequest(url string, body []byte) (*http.Response, error) {
req := c.newRequest(url, body)
resp, err := c.hc.Do(req)
if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) {
if err != nil && errors.Is(err, io.EOF) {
// it is likely connection became stale.
// So we do one more attempt in hope request will succeed.
// If not, the error should be handled by the caller as usual.
// This should help with https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4139
req = c.newRequest(url, body)
resp, err = c.hc.Do(req)
}