Skip to content

Commit

Permalink
drain before response.Body.Close() (istio#1772)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhengzheYang authored Dec 1, 2021
1 parent ec1526f commit 9770dc6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions isotope/service/pkg/srv/executable.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package srv

import (
"fmt"
"io"
"io/ioutil"
"math/rand"
"net/http"
Expand Down Expand Up @@ -91,8 +92,12 @@ func executeRequestCommand(

// Necessary for reusing HTTP/1.x "keep-alive" TCP connections.
// https://golang.org/pkg/net/http/#Response
defer response.Body.Close()
defer prometheus.RecordRequestSent(destName, uint64(cmd.Size))
defer func() {
// Drain and close the body to let the Transport reuse the connection
io.Copy(ioutil.Discard, response.Body)
response.Body.Close()
prometheus.RecordRequestSent(destName, uint64(cmd.Size))
}()

log.Debugf("%s responded with %s", destName, response.Status)
if response.StatusCode != http.StatusOK {
Expand Down

0 comments on commit 9770dc6

Please sign in to comment.