Skip to content

Commit 6f6925c

Browse files
committed
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 <[email protected]>
1 parent 669e718 commit 6f6925c

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

pkg/machine/gvproxy.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package machine
22

33
import (
4+
"errors"
45
"fmt"
6+
"io/fs"
57
"strconv"
68

79
"github.com/containers/podman/v5/pkg/machine/define"
@@ -11,7 +13,12 @@ import (
1113
func CleanupGVProxy(f define.VMFile) error {
1214
gvPid, err := f.Read()
1315
if err != nil {
14-
return fmt.Errorf("unable to read gvproxy pid file %s: %v", f.GetPath(), err)
16+
// The file will also be removed by gvproxy when it exits so
17+
// we need to account for the race and can just ignore it here.
18+
if errors.Is(err, fs.ErrNotExist) {
19+
return nil
20+
}
21+
return fmt.Errorf("unable to read gvproxy pid file: %v", err)
1522
}
1623
proxyPid, err := strconv.Atoi(string(gvPid))
1724
if err != nil {

pkg/machine/shim/host.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,9 @@ func Stop(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, dirs *machineDef
341341
if err != nil {
342342
return err
343343
}
344-
345-
defer func() {
346-
if err := machine.CleanupGVProxy(*gvproxyPidFile); err != nil {
347-
logrus.Errorf("unable to clean up gvproxy: %q", err)
348-
}
349-
}()
344+
if err := machine.CleanupGVProxy(*gvproxyPidFile); err != nil {
345+
return fmt.Errorf("unable to clean up gvproxy: %w", err)
346+
}
350347
}
351348

352349
return nil

0 commit comments

Comments
 (0)