From 9a02cbf751629830cdf9147d0935abb8fdf2dc17 Mon Sep 17 00:00:00 2001 From: Thomas Maier Date: Tue, 14 Aug 2018 16:38:07 +0200 Subject: [PATCH] ensure resp.Body is discarded to avoid broken tcp sockets (#348) Signed-off-by: Thomas Maier --- prober/http.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/prober/http.go b/prober/http.go index 5f2af69..bbc4543 100644 --- a/prober/http.go +++ b/prober/http.go @@ -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 { -- 2.25.1