ensure resp.Body is discarded to avoid broken tcp sockets (#348)
authorThomas Maier <contact@thomas-maier.net>
Tue, 14 Aug 2018 14:38:07 +0000 (16:38 +0200)
committerBrian Brazil <brian.brazil@robustperception.io>
Tue, 14 Aug 2018 14:38:07 +0000 (15:38 +0100)
Signed-off-by: Thomas Maier <contact@thomas-maier.net>
prober/http.go

index 5f2af6932d958f4896e52b6c6187c3ac818b2832..bbc454340a03589bca4ee35293326ca27e28ca9f 100644 (file)
@@ -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 {