Skip to content

Commit

Permalink
list: use Info(), fix race with delete
Browse files Browse the repository at this point in the history
Since commit 5516294 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 1a3ee49)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Mar 27, 2024
1 parent 498adf2 commit b6cceee
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion list.go
Expand Up @@ -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.
Expand Down

0 comments on commit b6cceee

Please sign in to comment.