From 6d63d165efe2fd415816d27ecdd075417203a381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Rod=C3=A1k?= Date: Thu, 9 Oct 2025 15:28:28 +0200 Subject: [PATCH] Fix flaky sysctl completion by handling /proc/sys errors gracefully MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- cmd/podman/common/completion.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd/podman/common/completion.go b/cmd/podman/common/completion.go index e860dc7073..5cad945e29 100644 --- a/cmd/podman/common/completion.go +++ b/cmd/podman/common/completion.go @@ -1979,12 +1979,16 @@ func AutocompleteSysctl(_ *cobra.Command, _ []string, toComplete string) ([]stri var completions []string sysPath := "/proc/sys" - err := filepath.Walk(sysPath, func(path string, info os.FileInfo, err error) error { + err := filepath.WalkDir(sysPath, func(path string, d fs.DirEntry, err error) error { if err != nil { - return err + // /proc/sys is a volatile virtual filesystem whose contents change dynamically. + // Skip directories on any error (race conditions, permission denied, etc.) to + // provide partial completion results rather than failing completely. + // See: https://github.com/containers/podman/issues/27252 + return filepath.SkipDir } - if !info.IsDir() { + if !d.IsDir() { rel, err := filepath.Rel(sysPath, path) if err != nil { return err