Skip to content

Commit

Permalink
Merge pull request #2078 from crazy-max/fix-rm-state-group
Browse files Browse the repository at this point in the history
build: fix racy localstate group removal
  • Loading branch information
tonistiigi authored Oct 18, 2023
2 parents ac93a7f + 1734abb commit 7d2c9d5
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions localstate/localstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,17 @@ func (ls *LocalState) RemoveBuilder(builderName string) error {
if err != nil {
return err
}

eg, _ := errgroup.WithContext(context.TODO())
for _, fi := range fis {
func(fi os.DirEntry) {
eg.Go(func() error {
return ls.RemoveBuilderNode(builderName, fi.Name())
})
}(fi)
}
if err := eg.Wait(); err != nil {
return err
if err := ls.RemoveBuilderNode(builderName, fi.Name()); err != nil {
return err
}
}

return os.RemoveAll(dir)
}

// RemoveBuilderNode removes all refs for a builder node.
// This func is not safe for concurrent use from multiple goroutines.
func (ls *LocalState) RemoveBuilderNode(builderName string, nodeName string) error {
if builderName == "" {
return errors.Errorf("builder name empty")
Expand Down

0 comments on commit 7d2c9d5

Please sign in to comment.