From 1413a284098d7cd4f3c620696bb3d4b32025576b Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Wed, 17 Jul 2024 19:08:25 +0200 Subject: [PATCH 1/2] podman auto-update: fix ErrNoSuchCtr race If a container is removed during the loop we should just ignore it. No reason to log this as error to the user. Fixes #23279 Signed-off-by: Paul Holzinger --- pkg/autoupdate/autoupdate.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/autoupdate/autoupdate.go b/pkg/autoupdate/autoupdate.go index 5b2ac829f2..df6627e378 100644 --- a/pkg/autoupdate/autoupdate.go +++ b/pkg/autoupdate/autoupdate.go @@ -4,6 +4,7 @@ package autoupdate import ( "context" + "errors" "fmt" "os" "sort" @@ -367,12 +368,15 @@ func (u *updater) assembleTasks(ctx context.Context) []error { u.unitToTasks = make(map[string][]*task) - errors := []error{} + errs := []error{} for _, c := range allContainers { ctr := c state, err := ctr.State() if err != nil { - errors = append(errors, err) + // container may have been removed in the meantime ignore it and not print errors + if !errors.Is(err, define.ErrNoSuchCtr) { + errs = append(errs, err) + } continue } // Only update running containers. @@ -389,7 +393,7 @@ func (u *updater) assembleTasks(ctx context.Context) []error { } policy, err := LookupPolicy(value) if err != nil { - errors = append(errors, err) + errs = append(errs, err) continue } if policy == PolicyDefault { @@ -400,11 +404,11 @@ func (u *updater) assembleTasks(ctx context.Context) []error { // stored as a label at container creation. unit, exists, err := u.systemdUnitForContainer(ctr, labels) if err != nil { - errors = append(errors, err) + errs = append(errs, err) continue } if !exists { - errors = append(errors, fmt.Errorf("auto-updating container %q: no %s label found", ctr.ID(), systemdDefine.EnvVariable)) + errs = append(errs, fmt.Errorf("auto-updating container %q: no %s label found", ctr.ID(), systemdDefine.EnvVariable)) continue } @@ -412,13 +416,13 @@ func (u *updater) assembleTasks(ctx context.Context) []error { image, exists := imageMap[id] if !exists { err := fmt.Errorf("internal error: no image found for ID %s", id) - errors = append(errors, err) + errs = append(errs, err) continue } rawImageName := ctr.RawImageName() if rawImageName == "" { - errors = append(errors, fmt.Errorf("locally auto-updating container %q: raw-image name is empty", ctr.ID())) + errs = append(errs, fmt.Errorf("locally auto-updating container %q: raw-image name is empty", ctr.ID())) continue } @@ -443,7 +447,7 @@ func (u *updater) assembleTasks(ctx context.Context) []error { u.unitToTasks[unit] = append(u.unitToTasks[unit], &t) } - return errors + return errs } // systemdUnitForContainer returns the name of the container's systemd unit. From 46f404489385afd47eb256dca964091e906ef1c1 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Wed, 17 Jul 2024 19:17:50 +0200 Subject: [PATCH 2/2] podman system df: fix fix ErrNoSuchCtr/Volume race When a container or volume is removed during the loop this is not a problem and we should just skip it as it is not a user bug and just a normal race. Signed-off-by: Paul Holzinger --- pkg/domain/infra/abi/system.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/pkg/domain/infra/abi/system.go b/pkg/domain/infra/abi/system.go index 2da7b6e5fc..5da8aba326 100644 --- a/pkg/domain/infra/abi/system.go +++ b/pkg/domain/infra/abi/system.go @@ -198,23 +198,24 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System iid, _ := c.Image() state, err := c.State() if err != nil { + if errors.Is(err, define.ErrNoSuchCtr) { + continue + } return nil, fmt.Errorf("failed to get state of container %s: %w", c.ID(), err) } conSize, err := c.RootFsSize() if err != nil { - if errors.Is(err, storage.ErrContainerUnknown) { - logrus.Error(fmt.Errorf("failed to get root file system size of container %s: %w", c.ID(), err)) - } else { - return nil, fmt.Errorf("failed to get root file system size of container %s: %w", c.ID(), err) + if errors.Is(err, storage.ErrContainerUnknown) || errors.Is(err, define.ErrNoSuchCtr) { + continue } + return nil, fmt.Errorf("failed to get root file system size of container %s: %w", c.ID(), err) } rwsize, err := c.RWSize() if err != nil { - if errors.Is(err, storage.ErrContainerUnknown) { - logrus.Error(fmt.Errorf("failed to get read/write size of container %s: %w", c.ID(), err)) - } else { - return nil, fmt.Errorf("failed to get read/write size of container %s: %w", c.ID(), err) + if errors.Is(err, storage.ErrContainerUnknown) || errors.Is(err, define.ErrNoSuchCtr) { + continue } + return nil, fmt.Errorf("failed to get read/write size of container %s: %w", c.ID(), err) } report := entities.SystemDfContainerReport{ ContainerID: c.ID(), @@ -241,6 +242,9 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System var reclaimableSize int64 mountPoint, err := v.MountPoint() if err != nil { + if errors.Is(err, define.ErrNoSuchVolume) { + continue + } return nil, err } if mountPoint == "" { @@ -255,6 +259,9 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System } inUse, err := v.VolumeInUse() if err != nil { + if errors.Is(err, define.ErrNoSuchVolume) { + continue + } return nil, err } if len(inUse) == 0 {