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 <[email protected]>
(cherry picked from commit 1a3ee49)
Signed-off-by: Kir Kolyshkin <[email protected]>
  • Loading branch information
kolyshkin committed Mar 27, 2024
1 parent 5fb60bd commit 7cf4d20
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion list.go
Original file line number Diff line number Diff line change
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 7cf4d20

Please sign in to comment.