mirror of https://github.com/containers/podman.git
pkg/api: top return error to client
Wait before sending status code 200 for the first top call and if that fails return a proper error code. This was leading to some confusion in [1] because podman just reported 200 but did not wirte anything back. [1] https://bugzilla.redhat.com/show_bug.cgi?id=2215572 Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
parent
49e0bde2bf
commit
d0505d6bac
|
@ -48,12 +48,8 @@ func TopContainer(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// We are committed now - all errors logged but not reported to client, ship has sailed
|
statusWritten := false
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
if f, ok := w.(http.Flusher); ok {
|
|
||||||
f.Flush()
|
|
||||||
}
|
|
||||||
|
|
||||||
encoder := json.NewEncoder(w)
|
encoder := json.NewEncoder(w)
|
||||||
|
|
||||||
|
@ -65,7 +61,11 @@ loop: // break out of for/select infinite` loop
|
||||||
default:
|
default:
|
||||||
output, err := c.Top(strings.Split(query.PsArgs, ","))
|
output, err := c.Top(strings.Split(query.PsArgs, ","))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Infof("Error from %s %q : %v", r.Method, r.URL, err)
|
if !statusWritten {
|
||||||
|
utils.InternalServerError(w, err)
|
||||||
|
} else {
|
||||||
|
logrus.Errorf("From %s %q : %v", r.Method, r.URL, err)
|
||||||
|
}
|
||||||
break loop
|
break loop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,9 +86,15 @@ loop: // break out of for/select infinite` loop
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := encoder.Encode(body); err != nil {
|
if err := encoder.Encode(body); err != nil {
|
||||||
logrus.Infof("Error from %s %q : %v", r.Method, r.URL, err)
|
if !statusWritten {
|
||||||
|
utils.InternalServerError(w, err)
|
||||||
|
} else {
|
||||||
|
logrus.Errorf("From %s %q : %v", r.Method, r.URL, err)
|
||||||
|
}
|
||||||
break loop
|
break loop
|
||||||
}
|
}
|
||||||
|
// after the first write we can no longer send a different status code
|
||||||
|
statusWritten = true
|
||||||
if f, ok := w.(http.Flusher); ok {
|
if f, ok := w.(http.Flusher); ok {
|
||||||
f.Flush()
|
f.Flush()
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,6 +132,15 @@ if root; then
|
||||||
podman rm -f $CTRNAME
|
podman rm -f $CTRNAME
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
CTRNAME=test123
|
||||||
|
podman run --name $CTRNAME -d $IMAGE top
|
||||||
|
t GET libpod/containers/$CTRNAME/top?ps_args=--invalid 500 \
|
||||||
|
.cause~".*unrecognized option.*"
|
||||||
|
t GET containers/$CTRNAME/top?ps_args=--invalid 500 \
|
||||||
|
.cause~".*unrecognized option.*"
|
||||||
|
|
||||||
|
podman rm -f $CTRNAME
|
||||||
|
|
||||||
# Issue #15765: make sure the memory limit is capped
|
# Issue #15765: make sure the memory limit is capped
|
||||||
if root; then
|
if root; then
|
||||||
CTRNAME=ctr-with-limit
|
CTRNAME=ctr-with-limit
|
||||||
|
|
Loading…
Reference in New Issue