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 <kolyshkin@gmail.com>
(cherry picked from commit 1a3ee4966c)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2022-01-25 15:33:25 -08:00
parent 09214f21da
commit 986edbe60f
+5 -1
View File
@@ -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.