Skip to content

Commit c4ade21

Browse files
committed
Fix flaky sysctl completion by handling /proc/sys race conditions
Ignore ENOENT errors during /proc/sys traversal as entries can disappear between directory enumeration and file access. Continue logging other errors for investigation. Fixes: #27252 Signed-off-by: Jan Rodák <[email protected]>
1 parent 685a448 commit c4ade21

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

cmd/podman/common/completion.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package common
22

33
import (
44
"bufio"
5+
"errors"
56
"fmt"
67
"io/fs"
78
"net"
@@ -22,6 +23,7 @@ import (
2223
systemdDefine "github.com/containers/podman/v5/pkg/systemd/define"
2324
"github.com/containers/podman/v5/pkg/util"
2425
securejoin "github.com/cyphar/filepath-securejoin"
26+
"github.com/sirupsen/logrus"
2527
"github.com/spf13/cobra"
2628
libimageDefine "go.podman.io/common/libimage/define"
2729
"go.podman.io/common/libnetwork/types"
@@ -1981,6 +1983,13 @@ func AutocompleteSysctl(_ *cobra.Command, _ []string, toComplete string) ([]stri
19811983

19821984
err := filepath.Walk(sysPath, func(path string, info os.FileInfo, err error) error {
19831985
if err != nil {
1986+
// /proc/sys is a volatile virtual filesystem whose contents can change rapidly.
1987+
// Handle race conditions where entries disappear between directory enumeration
1988+
// and file access attempts - this is expected behavior in busy CI environments.
1989+
// See: https://github.com/containers/podman/issues/27252
1990+
if errors.Is(err, fs.ErrNotExist) {
1991+
return nil
1992+
}
19841993
return err
19851994
}
19861995

@@ -2000,6 +2009,7 @@ func AutocompleteSysctl(_ *cobra.Command, _ []string, toComplete string) ([]stri
20002009
})
20012010

20022011
if err != nil {
2012+
logrus.Errorf("failed to scan sysctl parameters in %q: %v", sysPath, err)
20032013
return nil, cobra.ShellCompDirectiveError
20042014
}
20052015

0 commit comments

Comments
 (0)