mirror of
https://github.com/openfaas/faas.git
synced 2025-06-08 16:26:47 +00:00
Remember to close HTTP body from response
Flagged via community in: https://github.com/openfaas/faas/pull/1836 Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alex@openfaas.com>
This commit is contained in:
parent
8d5dcdfa4c
commit
667577f3ce
@ -86,7 +86,7 @@ func (e *Exporter) StartServiceWatcher(endpointURL url.URL, metricsOptions Metri
|
|||||||
|
|
||||||
namespaces, err := e.getNamespaces(endpointURL)
|
namespaces, err := e.getNamespaces(endpointURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Printf("Error listing namespaces: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
services := []types.FunctionStatus{}
|
services := []types.FunctionStatus{}
|
||||||
@ -95,7 +95,7 @@ func (e *Exporter) StartServiceWatcher(endpointURL url.URL, metricsOptions Metri
|
|||||||
if len(namespaces) == 0 {
|
if len(namespaces) == 0 {
|
||||||
services, err = e.getFunctions(endpointURL, e.FunctionNamespace)
|
services, err = e.getFunctions(endpointURL, e.FunctionNamespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Printf("Error getting functions from: %s, error: %s", e.FunctionNamespace, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
e.services = services
|
e.services = services
|
||||||
@ -103,7 +103,7 @@ func (e *Exporter) StartServiceWatcher(endpointURL url.URL, metricsOptions Metri
|
|||||||
for _, namespace := range namespaces {
|
for _, namespace := range namespaces {
|
||||||
nsServices, err := e.getFunctions(endpointURL, namespace)
|
nsServices, err := e.getFunctions(endpointURL, namespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Printf("Error getting functions from: %s, error: %s", e.FunctionNamespace, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
services = append(services, nsServices...)
|
services = append(services, nsServices...)
|
||||||
@ -112,7 +112,6 @@ func (e *Exporter) StartServiceWatcher(endpointURL url.URL, metricsOptions Metri
|
|||||||
|
|
||||||
e.services = services
|
e.services = services
|
||||||
|
|
||||||
break
|
|
||||||
case <-quit:
|
case <-quit:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -159,14 +158,22 @@ func (e *Exporter) getFunctions(endpointURL url.URL, namespace string) ([]types.
|
|||||||
return services, err
|
return services, err
|
||||||
}
|
}
|
||||||
|
|
||||||
bytesOut, readErr := io.ReadAll(res.Body)
|
var body []byte
|
||||||
if readErr != nil {
|
if res.Body != nil {
|
||||||
return services, readErr
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
if b, err := io.ReadAll(res.Body); err != nil {
|
||||||
|
return services, err
|
||||||
|
} else {
|
||||||
|
body = b
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return services, fmt.Errorf("no response body from /system/functions")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.Unmarshal(bytesOut, &services); err != nil {
|
if err := json.Unmarshal(body, &services); err != nil {
|
||||||
return services, fmt.Errorf("error unmarshalling response: %s, error: %s",
|
return services, fmt.Errorf("error unmarshalling response: %s, error: %s",
|
||||||
string(bytesOut), err)
|
string(body), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return services, nil
|
return services, nil
|
||||||
@ -193,13 +200,20 @@ func (e *Exporter) getNamespaces(endpointURL url.URL) ([]string, error) {
|
|||||||
return namespaces, nil
|
return namespaces, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
bytesOut, readErr := io.ReadAll(res.Body)
|
var body []byte
|
||||||
if readErr != nil {
|
if res.Body != nil {
|
||||||
return namespaces, readErr
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
if b, err := io.ReadAll(res.Body); err != nil {
|
||||||
|
return namespaces, err
|
||||||
|
} else {
|
||||||
|
body = b
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.Unmarshal(bytesOut, &namespaces); err != nil {
|
if err := json.Unmarshal(body, &namespaces); err != nil {
|
||||||
return namespaces, fmt.Errorf("error unmarshalling response: %s, error: %s", string(bytesOut), err)
|
return namespaces, fmt.Errorf("error unmarshalling response: %s, error: %s", string(body), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return namespaces, nil
|
return namespaces, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user