From 81003f2d0884d8aa92a77c0a31e00165bdca1518 Mon Sep 17 00:00:00 2001 From: Brent Baude Date: Tue, 6 Aug 2024 14:01:48 -0500 Subject: [PATCH] Ignore ERROR_SHARING_VIOLATION error on windows When removing the gvproxy pid file, under CI conditions we could hit a case where the PID file being removed seemed to have an open handle on it still. I could not find anything in podman that left an open handle and gvproxy would have quit before this, so we think it is likely another process holding it. I could not find root cause with CI because I could not trip the flake. this new code allows windows (specifically hyperv bc WSL does not use GVProxy) to ignore an ERROR_SHARING_VIOLATION. Signed-off-by: Brent Baude --- pkg/machine/gvproxy.go | 2 +- pkg/machine/gvproxy_unix.go | 7 +++++++ pkg/machine/gvproxy_windows.go | 13 +++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/machine/gvproxy.go b/pkg/machine/gvproxy.go index fc236038eb..2c083cb20b 100644 --- a/pkg/machine/gvproxy.go +++ b/pkg/machine/gvproxy.go @@ -27,5 +27,5 @@ func CleanupGVProxy(f define.VMFile) error { if err := waitOnProcess(proxyPid); err != nil { return err } - return f.Delete() + return removeGVProxyPIDFile(f) } diff --git a/pkg/machine/gvproxy_unix.go b/pkg/machine/gvproxy_unix.go index 20869d583e..60f4399654 100644 --- a/pkg/machine/gvproxy_unix.go +++ b/pkg/machine/gvproxy_unix.go @@ -8,6 +8,7 @@ import ( "syscall" "time" + "github.com/containers/podman/v5/pkg/machine/define" psutil "github.com/shirou/gopsutil/v3/process" "github.com/sirupsen/logrus" "golang.org/x/sys/unix" @@ -72,3 +73,9 @@ func waitOnProcess(processID int) error { } return backoffForProcess(p) } + +// removeGVProxyPIDFile is just a wrapper to vmfile delete so we handle differently +// on windows +func removeGVProxyPIDFile(f define.VMFile) error { + return f.Delete() +} diff --git a/pkg/machine/gvproxy_windows.go b/pkg/machine/gvproxy_windows.go index d0d5f1b725..8d572c42b1 100644 --- a/pkg/machine/gvproxy_windows.go +++ b/pkg/machine/gvproxy_windows.go @@ -1,11 +1,14 @@ package machine import ( + "errors" "os" "time" + "github.com/containers/podman/v5/pkg/machine/define" "github.com/containers/winquit/pkg/winquit" "github.com/sirupsen/logrus" + "golang.org/x/sys/windows" ) func waitOnProcess(processID int) error { @@ -44,3 +47,13 @@ func waitOnProcess(processID int) error { return nil } + +// removeGVProxyPIDFile special wrapper for deleting the GVProxyPIDFile on windows in case +// the file has an open handle which we will ignore. unix does not have this problem +func removeGVProxyPIDFile(f define.VMFile) error { + err := f.Delete() + if err != nil && !errors.Is(err, windows.ERROR_SHARING_VIOLATION) { + return err + } + return nil +}