daemon control / jsonclient: fix connection leak due to open request body

Also:
- Defensive measures in control http server (1s timeouts)
(prevent the leak, even if request body is not closed)
- Add prometheus metrics to track control socket latencies
(were used for debugging)
This commit is contained in:
Christian Schwarz
2018-09-13 12:44:46 +02:00
parent fa47667f31
commit 6c3f442f13
2 changed files with 36 additions and 3 deletions

View File

@@ -30,7 +30,10 @@ func jsonRequestResponse(c http.Client, endpoint string, req interface{}, res in
resp, err := c.Post("http://unix"+endpoint, "application/json", &buf)
if err != nil {
return err
} else if resp.StatusCode != http.StatusOK {
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
var msg bytes.Buffer
io.CopyN(&msg, resp.Body, 4096)
return errors.Errorf("%s", msg.String())