From d5057f6d04748cec470748e9dd04b994be2633b5 Mon Sep 17 00:00:00 2001
From: Aliaksandr Valialkin <valyala@gmail.com>
Date: Mon, 27 Jul 2020 17:31:36 +0300
Subject: [PATCH] app/vmagent/remotewrite: create new request on failure to
 send a block of data to remote storage

Previously the request body was already consumed before the retry, so this led to the following error:

    http: ContentLength=... with Body length 0
---
 app/vmagent/remotewrite/client.go | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/app/vmagent/remotewrite/client.go b/app/vmagent/remotewrite/client.go
index 7dcadcdfe3..77c92ebf64 100644
--- a/app/vmagent/remotewrite/client.go
+++ b/app/vmagent/remotewrite/client.go
@@ -182,6 +182,9 @@ func (c *client) runWorker() {
 }
 
 func (c *client) sendBlock(block []byte) {
+	retryDuration := time.Second
+
+again:
 	req, err := http.NewRequest("POST", c.remoteWriteURL, bytes.NewBuffer(block))
 	if err != nil {
 		logger.Panicf("BUG: unexected error from http.NewRequest(%q): %s", c.remoteWriteURL, err)
@@ -195,9 +198,6 @@ func (c *client) sendBlock(block []byte) {
 		req.Header.Set("Authorization", c.authHeader)
 	}
 
-	retryDuration := time.Second
-
-again:
 	startTime := time.Now()
 	resp, err := c.hc.Do(req)
 	c.requestDuration.UpdateDuration(startTime)