discovery/marathon: fix leaked connections (#4915)

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
Simon Pasquier 2018-11-27 14:58:27 +01:00 committed by GitHub
parent 328d81999a
commit 0bb810d126
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 17 deletions

View File

@ -353,30 +353,18 @@ func fetchApps(client *http.Client, url string) (*AppList, error) {
if err != nil {
return nil, err
}
defer resp.Body.Close()
if (resp.StatusCode < 200) || (resp.StatusCode >= 300) {
return nil, fmt.Errorf("Non 2xx status '%v' response during marathon service discovery", resp.StatusCode)
}
body, err := ioutil.ReadAll(resp.Body)
var apps AppList
err = json.NewDecoder(resp.Body).Decode(&apps)
if err != nil {
return nil, err
return nil, fmt.Errorf("%q: %v", url, err)
}
apps, err := parseAppJSON(body)
if err != nil {
return nil, fmt.Errorf("%v in %s", err, url)
}
return apps, nil
}
func parseAppJSON(body []byte) (*AppList, error) {
apps := &AppList{}
err := json.Unmarshal(body, apps)
if err != nil {
return nil, err
}
return apps, nil
return &apps, nil
}
// RandomAppsURL randomly selects a server from an array and creates

View File

@ -530,6 +530,7 @@ func (h *Handler) consoles(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusNotFound)
return
}
defer file.Close()
text, err := ioutil.ReadAll(file)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)