Skip to content

Commit 6d63d16

Browse files
committed
Fix flaky sysctl completion by handling /proc/sys errors gracefully
Skip directories on any error during /proc/sys traversal (race conditions, permission denied, etc.) to provide partial completion results rather than failing completely. Use filepath.WalkDir for better performance. Fixes: #27252 Signed-off-by: Jan Rodák <[email protected]>
1 parent 685a448 commit 6d63d16

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

cmd/podman/common/completion.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,12 +1979,16 @@ func AutocompleteSysctl(_ *cobra.Command, _ []string, toComplete string) ([]stri
19791979
var completions []string
19801980
sysPath := "/proc/sys"
19811981

1982-
err := filepath.Walk(sysPath, func(path string, info os.FileInfo, err error) error {
1982+
err := filepath.WalkDir(sysPath, func(path string, d fs.DirEntry, err error) error {
19831983
if err != nil {
1984-
return err
1984+
// /proc/sys is a volatile virtual filesystem whose contents change dynamically.
1985+
// Skip directories on any error (race conditions, permission denied, etc.) to
1986+
// provide partial completion results rather than failing completely.
1987+
// See: https://github.com/containers/podman/issues/27252
1988+
return filepath.SkipDir
19851989
}
19861990

1987-
if !info.IsDir() {
1991+
if !d.IsDir() {
19881992
rel, err := filepath.Rel(sysPath, path)
19891993
if err != nil {
19901994
return err

0 commit comments

Comments
 (0)