From 6f6925cca4f00ada74977709471ccbfe70184a37 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 22 Feb 2024 12:33:10 +0100 Subject: [PATCH] pkg/machine: ignore gvproxy pidfile not exists error When gvproxy exits it will delete the pidfile itself so we need to account for that and juts ignore the case, it just means gvproxy was able to exit successfully on its own. Also remove the useless defer and return the error so we can get an error exit code not just a print on stderr. Currently it shows this error which is not helpful to any user: unable to clean up gvproxy: "unable to read gvproxy pid file /run/user/1000/podman/gvproxy.pid: open /run/user/1000/podman/gvproxy.pid: no such file or directory" [NO NEW TESTS NEEDED] TODO: make machine tests check stderr for such things. Signed-off-by: Paul Holzinger --- pkg/machine/gvproxy.go | 9 ++++++++- pkg/machine/shim/host.go | 9 +++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pkg/machine/gvproxy.go b/pkg/machine/gvproxy.go index b1789d3e08..fc236038eb 100644 --- a/pkg/machine/gvproxy.go +++ b/pkg/machine/gvproxy.go @@ -1,7 +1,9 @@ package machine import ( + "errors" "fmt" + "io/fs" "strconv" "github.com/containers/podman/v5/pkg/machine/define" @@ -11,7 +13,12 @@ import ( func CleanupGVProxy(f define.VMFile) error { gvPid, err := f.Read() if err != nil { - return fmt.Errorf("unable to read gvproxy pid file %s: %v", f.GetPath(), err) + // The file will also be removed by gvproxy when it exits so + // we need to account for the race and can just ignore it here. + if errors.Is(err, fs.ErrNotExist) { + return nil + } + return fmt.Errorf("unable to read gvproxy pid file: %v", err) } proxyPid, err := strconv.Atoi(string(gvPid)) if err != nil { diff --git a/pkg/machine/shim/host.go b/pkg/machine/shim/host.go index 8ecd99d9be..d2b776c8bf 100644 --- a/pkg/machine/shim/host.go +++ b/pkg/machine/shim/host.go @@ -341,12 +341,9 @@ func Stop(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, dirs *machineDef if err != nil { return err } - - defer func() { - if err := machine.CleanupGVProxy(*gvproxyPidFile); err != nil { - logrus.Errorf("unable to clean up gvproxy: %q", err) - } - }() + if err := machine.CleanupGVProxy(*gvproxyPidFile); err != nil { + return fmt.Errorf("unable to clean up gvproxy: %w", err) + } } return nil