discovery/marathon: fix leaked connections (#4915)
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
parent
328d81999a
commit
0bb810d126
|
@ -353,30 +353,18 @@ func fetchApps(client *http.Client, url string) (*AppList, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if (resp.StatusCode < 200) || (resp.StatusCode >= 300) {
|
if (resp.StatusCode < 200) || (resp.StatusCode >= 300) {
|
||||||
return nil, fmt.Errorf("Non 2xx status '%v' response during marathon service discovery", resp.StatusCode)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf("%q: %v", url, err)
|
||||||
}
|
}
|
||||||
|
return &apps, nil
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RandomAppsURL randomly selects a server from an array and creates
|
// RandomAppsURL randomly selects a server from an array and creates
|
||||||
|
|
|
@ -530,6 +530,7 @@ func (h *Handler) consoles(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Error(w, err.Error(), http.StatusNotFound)
|
http.Error(w, err.Error(), http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer file.Close()
|
||||||
text, err := ioutil.ReadAll(file)
|
text, err := ioutil.ReadAll(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
|
Loading…
Reference in New Issue