From 9a0c0b2eef962bdb63372ed0ccd2bb6b1e5de3b8 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Wed, 6 Nov 2024 12:11:23 +0100 Subject: [PATCH] volume ls: fix race that caused it to fail If volume ls was called while another volume was removed at the right time it could have failed with "no such volume" as we did not ignore such error during listing. As we list things and this no longer exists the correct thing is to ignore the error and continue like we do with containers, pods, etc... This was pretty easy to reproduce with these two commands running in different terminals: while :; do bin/podman volume create test && bin/podman volume rm test || break; done while :; do bin/podman volume ls || break ; done I have a slight feeling that this might solve #23913 but I am not to sure there so I am not adding a Fixes here. Signed-off-by: Paul Holzinger --- pkg/api/handlers/compat/volumes.go | 3 +++ pkg/api/handlers/libpod/volumes.go | 26 +++----------------------- pkg/domain/infra/abi/volumes.go | 3 +++ 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/pkg/api/handlers/compat/volumes.go b/pkg/api/handlers/compat/volumes.go index 943190841b..9ddda58a04 100644 --- a/pkg/api/handlers/compat/volumes.go +++ b/pkg/api/handlers/compat/volumes.go @@ -60,6 +60,9 @@ func ListVolumes(w http.ResponseWriter, r *http.Request) { for _, v := range vols { mp, err := v.MountPoint() if err != nil { + if errors.Is(err, define.ErrNoSuchVolume) { + continue + } utils.InternalServerError(w, err) return } diff --git a/pkg/api/handlers/libpod/volumes.go b/pkg/api/handlers/libpod/volumes.go index 986052e924..545f3b3f55 100644 --- a/pkg/api/handlers/libpod/volumes.go +++ b/pkg/api/handlers/libpod/volumes.go @@ -121,33 +121,13 @@ func ListVolumes(w http.ResponseWriter, r *http.Request) { return } - volumeFilters := []libpod.VolumeFilter{} - for filter, filterValues := range *filterMap { - filterFunc, err := filters.GenerateVolumeFilters(filter, filterValues, runtime) - if err != nil { - utils.InternalServerError(w, err) - return - } - volumeFilters = append(volumeFilters, filterFunc) - } - - vols, err := runtime.Volumes(volumeFilters...) + ic := abi.ContainerEngine{Libpod: runtime} + volumeConfigs, err := ic.VolumeList(r.Context(), entities.VolumeListOptions{Filter: *filterMap}) if err != nil { utils.InternalServerError(w, err) return } - volumeConfigs := make([]*entities.VolumeListReport, 0, len(vols)) - for _, v := range vols { - inspectOut, err := v.Inspect() - if err != nil { - utils.InternalServerError(w, err) - return - } - config := entities.VolumeConfigResponse{ - InspectVolumeData: *inspectOut, - } - volumeConfigs = append(volumeConfigs, &entities.VolumeListReport{VolumeConfigResponse: config}) - } + utils.WriteResponse(w, http.StatusOK, volumeConfigs) } diff --git a/pkg/domain/infra/abi/volumes.go b/pkg/domain/infra/abi/volumes.go index 7ecc29324f..77c99559e5 100644 --- a/pkg/domain/infra/abi/volumes.go +++ b/pkg/domain/infra/abi/volumes.go @@ -164,6 +164,9 @@ func (ic *ContainerEngine) VolumeList(ctx context.Context, opts entities.VolumeL for _, v := range vols { inspectOut, err := v.Inspect() if err != nil { + if errors.Is(err, define.ErrNoSuchVolume) { + continue + } return nil, err } config := entities.VolumeConfigResponse{