Skip to content

Commit

Permalink
drain request body to allow connection reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
barrettj12 committed Aug 4, 2023
1 parent c551a60 commit c3c8b45
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internals/overlord/logstate/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ func (c *lokiClient) Flush(ctx context.Context) error {
if err != nil {
return err
}
defer func() { _ = resp.Body.Close() }()
defer func() {
// Drain request body to allow connection reuse
// see https://pkg.go.dev/net/http#Response.Body
_, _ = io.Copy(io.Discard, io.LimitReader(resp.Body, 1024*1024))
_ = resp.Body.Close()
}()

// Check response status code to see if it was successful
if code := resp.StatusCode; code < 200 || code >= 300 {
Expand Down

0 comments on commit c3c8b45

Please sign in to comment.