build: fix racy localstate group removal

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax 2023-10-14 17:44:22 +02:00
parent ac93a7fbfb
commit 1734abbb76
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
1 changed files with 5 additions and 10 deletions

View File

@ -127,22 +127,17 @@ func (ls *LocalState) RemoveBuilder(builderName string) error {
if err != nil { if err != nil {
return err return err
} }
eg, _ := errgroup.WithContext(context.TODO())
for _, fi := range fis { for _, fi := range fis {
func(fi os.DirEntry) { if err := ls.RemoveBuilderNode(builderName, fi.Name()); err != nil {
eg.Go(func() error { return err
return ls.RemoveBuilderNode(builderName, fi.Name()) }
})
}(fi)
}
if err := eg.Wait(); err != nil {
return err
} }
return os.RemoveAll(dir) 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 { func (ls *LocalState) RemoveBuilderNode(builderName string, nodeName string) error {
if builderName == "" { if builderName == "" {
return errors.Errorf("builder name empty") return errors.Errorf("builder name empty")