Skip to content

Commit

Permalink
ensure resp.Body is discarded to avoid broken tcp sockets (#348)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Maier <[email protected]>
  • Loading branch information
tmsmr authored and brian-brazil committed Aug 14, 2018
1 parent 2a04b8e commit 9a02cbf
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion prober/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,10 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
if err != nil && resp == nil {
level.Error(logger).Log("msg", "Error for HTTP request", "err", err)
} else {
defer resp.Body.Close()
defer func() {
io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
}()
level.Info(logger).Log("msg", "Received HTTP response", "status_code", resp.StatusCode)
if len(httpConfig.ValidStatusCodes) != 0 {
for _, code := range httpConfig.ValidStatusCodes {
Expand Down

0 comments on commit 9a02cbf

Please sign in to comment.