From f1c777a503a9303131defbbfaeadbb7463f95271 Mon Sep 17 00:00:00 2001 From: Zhengzhe Yang Date: Wed, 1 Dec 2021 22:44:31 +0000 Subject: [PATCH] drain before response.Body.Close() --- isotope/service/pkg/srv/executable.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/isotope/service/pkg/srv/executable.go b/isotope/service/pkg/srv/executable.go index 00fef96ea1..ba14eacc82 100644 --- a/isotope/service/pkg/srv/executable.go +++ b/isotope/service/pkg/srv/executable.go @@ -16,6 +16,7 @@ package srv import ( "fmt" + "io" "io/ioutil" "math/rand" "net/http" @@ -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 {