diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-04-23 07:20:49 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-23 07:20:49 -0400 |
commit | afdea0dccd06a907d04596375e056134dc4f5b33 (patch) | |
tree | 1356649fc2968afa6ee069cc549fec30f3209a11 | |
parent | 8465626e312a582e434851e6e562974cb3e2e1f8 (diff) | |
parent | 2df5c6383f6f6ff1f40975450a48abeff57dbd9b (diff) | |
download | podman-afdea0dccd06a907d04596375e056134dc4f5b33.tar.gz podman-afdea0dccd06a907d04596375e056134dc4f5b33.tar.bz2 podman-afdea0dccd06a907d04596375e056134dc4f5b33.zip |
Merge pull request #10121 from SoMuchForSubtlety/master
Fix removal race condition in ListContainers
-rw-r--r-- | pkg/api/handlers/compat/containers.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/pkg/api/handlers/compat/containers.go b/pkg/api/handlers/compat/containers.go index e7146a5d8..d97a4d3bd 100644 --- a/pkg/api/handlers/compat/containers.go +++ b/pkg/api/handlers/compat/containers.go @@ -26,6 +26,7 @@ import ( "github.com/docker/go-units" "github.com/gorilla/schema" "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) func RemoveContainer(w http.ResponseWriter, r *http.Request) { @@ -148,14 +149,19 @@ func ListContainers(w http.ResponseWriter, r *http.Request) { containers = containers[:query.Limit] } } - var list = make([]*handlers.Container, len(containers)) - for i, ctnr := range containers { + list := make([]*handlers.Container, 0, len(containers)) + for _, ctnr := range containers { api, err := LibpodToContainer(ctnr, query.Size) 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) return } - list[i] = api + list = append(list, api) } utils.WriteResponse(w, http.StatusOK, list) } |