Skip to content

Commit 70dddb6

Browse files
authored
querier: exhaust response body before closing (#4429)
Exhaust the whole body of the response before closing to facilitate re-use of keep-alive connections as per the documentation here: https://pkg.go.dev/net/http#Client.Get ``` Caller should close resp.Body when done reading from it. ``` Also some discussion here: https://groups.google.com/g/golang-nuts/c/148riho42sU #4428 Signed-off-by: Giedrius Statkevičius <[email protected]>
1 parent 88171a5 commit 70dddb6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pkg/querier/queryrange/roundtrip.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package queryrange
1818
import (
1919
"context"
2020
"flag"
21+
"io"
22+
"io/ioutil"
2123
"net/http"
2224
"strings"
2325
"time"
@@ -289,7 +291,10 @@ func (q roundTripper) Do(ctx context.Context, r Request) (Response, error) {
289291
if err != nil {
290292
return nil, err
291293
}
292-
defer func() { _ = response.Body.Close() }()
294+
defer func() {
295+
io.Copy(ioutil.Discard, io.LimitReader(response.Body, 1024))
296+
_ = response.Body.Close()
297+
}()
293298

294299
return q.codec.DecodeResponse(ctx, response, r)
295300
}

0 commit comments

Comments
 (0)