From b6cceee846f1c263f289896595feda12b88c124b Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 25 Jan 2022 15:33:25 -0800 Subject: [PATCH] list: use Info(), fix race with delete Since commit 551629417 we can (and should) use Info() to get access to file stat. Do this. While going over directory entries, a parallel runc delete can remove an entry, and with the current code it results in a fatal error (which was not observed in practice, but looks quite possible). To fix, add a special case to continue on ErrNotExist. Signed-off-by: Kir Kolyshkin (cherry picked from commit 1a3ee4966ce58abd243cb6aeb55fb561dca31a56) Signed-off-by: Kir Kolyshkin --- list.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/list.go b/list.go index bf6ce792e69..3fb9917248f 100644 --- a/list.go +++ b/list.go @@ -130,8 +130,12 @@ func getContainers(context *cli.Context) ([]containerState, error) { if !item.IsDir() { continue } - st, err := os.Stat(filepath.Join(absRoot, item.Name())) + st, err := item.Info() if err != nil { + if errors.Is(err, os.ErrNotExist) { + // Possible race with runc delete. + continue + } fatal(err) } // This cast is safe on Linux.