diff --git a/metrics/librato/client.go b/metrics/librato/client.go index 89ecb9ec64da5..053e1811d4ed6 100644 --- a/metrics/librato/client.go +++ b/metrics/librato/client.go @@ -87,9 +87,11 @@ func (lc *LibratoClient) PostMetrics(batch Batch) (err error) { req.Header.Set("Content-Type", "application/json") req.SetBasicAuth(lc.Email, lc.Token) - if resp, err = http.DefaultClient.Do(req); err != nil { + resp, err = http.DefaultClient.Do(req) + if err != nil { return } + defer resp.Body.Close() if resp.StatusCode != http.StatusOK { var body []byte diff --git a/node/node_test.go b/node/node_test.go index df97c66c71cab..b733ea517492a 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -651,5 +651,6 @@ func doHTTPRequest(t *testing.T, req *http.Request) *http.Response { if err != nil { t.Error("could not issue a GET request to the given endpoint", err) } + t.Cleanup(func() { resp.Body.Close() }) return resp } diff --git a/p2p/simulations/mocker_test.go b/p2p/simulations/mocker_test.go index 32b566ecee7e8..8cc84f8e83b80 100644 --- a/p2p/simulations/mocker_test.go +++ b/p2p/simulations/mocker_test.go @@ -127,6 +127,7 @@ func TestMocker(t *testing.T) { if err != nil { t.Fatalf("Could not start mocker: %s", err) } + resp.Body.Close() if resp.StatusCode != 200 { t.Fatalf("Invalid Status Code received for starting mocker, expected 200, got %d", resp.StatusCode) } @@ -148,15 +149,17 @@ func TestMocker(t *testing.T) { if err != nil { t.Fatalf("Could not stop mocker: %s", err) } + resp.Body.Close() if resp.StatusCode != 200 { t.Fatalf("Invalid Status Code received for stopping mocker, expected 200, got %d", resp.StatusCode) } //reset the network - _, err = http.Post(s.URL+"/reset", "", nil) + resp, err = http.Post(s.URL+"/reset", "", nil) if err != nil { t.Fatalf("Could not reset network: %s", err) } + resp.Body.Close() //now the number of nodes in the network should be zero nodes_info, err = client.GetNodes() diff --git a/rpc/http_test.go b/rpc/http_test.go index 73920b44f09a3..73124fb3508af 100644 --- a/rpc/http_test.go +++ b/rpc/http_test.go @@ -92,6 +92,7 @@ func confirmHTTPRequestYieldsStatusCode(t *testing.T, method, contentType, body if err != nil { t.Fatalf("request failed: %v", err) } + resp.Body.Close() confirmStatusCode(t, resp.StatusCode, expectedStatusCode) }