handle racy updates to globalSite config (#19750)

```
==================
WARNING: DATA RACE
Read at 0x0000082be990 by goroutine 205:
  github.com/minio/minio/cmd.setCommonHeaders()

Previous write at 0x0000082be990 by main goroutine:
  github.com/minio/minio/cmd.lookupConfigs()
```
This commit is contained in:
Harshavardhana
2024-05-16 16:13:47 -07:00
committed by GitHub
parent aa3fde1784
commit 08d74819b6
31 changed files with 95 additions and 62 deletions

View File

@@ -24,6 +24,7 @@ import (
"regexp"
"sort"
"strings"
"sync"
"github.com/minio/madmin-go/v3"
"github.com/minio/minio-go/v7/pkg/set"
@@ -544,10 +545,36 @@ var (
}
)
var siteLK sync.RWMutex
// Site - holds site info - name and region.
type Site struct {
Name string
Region string
name string
region string
}
// Update safe update the new site name and region
func (s *Site) Update(n Site) {
siteLK.Lock()
s.name = n.name
s.region = n.region
siteLK.Unlock()
}
// Name returns currently configured site name
func (s *Site) Name() string {
siteLK.RLock()
defer siteLK.RUnlock()
return s.name
}
// Region returns currently configured site region
func (s *Site) Region() string {
siteLK.RLock()
defer siteLK.RUnlock()
return s.region
}
var validRegionRegex = regexp.MustCompile("^[a-zA-Z][a-zA-Z0-9-_-]+$")
@@ -590,7 +617,7 @@ func LookupSite(siteKV KVS, regionKV KVS) (s Site, err error) {
region)
return
}
s.Region = region
s.region = region
}
name := env.Get(EnvSiteName, siteKV.Get(NameKey))
@@ -601,7 +628,7 @@ func LookupSite(siteKV KVS, regionKV KVS) (s Site, err error) {
name)
return
}
s.Name = name
s.name = name
}
return
}