mirror of
https://github.com/containers/podman.git
synced 2025-06-26 04:46:57 +08:00
Fix removal race condition in ListContainers
It is possible that a container is removed between fetching the initial list of containers and the second access during conversion. Closes #10120 [NO TESTS NEEDED] Signed-off-by: Jakob Ahrer <jakob@ahrer.dev>
This commit is contained in:
@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/docker/go-units"
|
"github.com/docker/go-units"
|
||||||
"github.com/gorilla/schema"
|
"github.com/gorilla/schema"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RemoveContainer(w http.ResponseWriter, r *http.Request) {
|
func RemoveContainer(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -148,14 +149,19 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
|
|||||||
containers = containers[:query.Limit]
|
containers = containers[:query.Limit]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var list = make([]*handlers.Container, len(containers))
|
list := make([]*handlers.Container, 0, len(containers))
|
||||||
for i, ctnr := range containers {
|
for _, ctnr := range containers {
|
||||||
api, err := LibpodToContainer(ctnr, query.Size)
|
api, err := LibpodToContainer(ctnr, query.Size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if errors.Cause(err) == define.ErrNoSuchCtr {
|
||||||
|
// container was removed between the initial fetch of the list and conversion
|
||||||
|
logrus.Debugf("Container %s removed between initial fetch and conversion, ignoring in output", ctnr.ID())
|
||||||
|
continue
|
||||||
|
}
|
||||||
utils.InternalServerError(w, err)
|
utils.InternalServerError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
list[i] = api
|
list = append(list, api)
|
||||||
}
|
}
|
||||||
utils.WriteResponse(w, http.StatusOK, list)
|
utils.WriteResponse(w, http.StatusOK, list)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user