Fix BackendInfo() race (#18305)

`GetParityForSC` has a value receiver, so Config is copied before the lock is obtained.

Make it pointer receiver.

Fixes:

```
WARNING: DATA RACE
Read at 0x0000079cdd10 by goroutine 190:
  github.com/minio/minio/cmd.(*erasureServerPools).BackendInfo()
      github.com/minio/minio/cmd/erasure-server-pool.go:579 +0x6f
  github.com/minio/minio/cmd.(*erasureServerPools).LocalStorageInfo()
      github.com/minio/minio/cmd/erasure-server-pool.go:614 +0x3c6
  github.com/minio/minio/cmd.(*peerRESTServer).LocalStorageInfoHandler()
      github.com/minio/minio/cmd/peer-rest-server.go:347 +0x4ea
  github.com/minio/minio/cmd.(*peerRESTServer).LocalStorageInfoHandler-fm()
...

WARNING: DATA RACE
Read at 0x0000079cdd10 by goroutine 190:
  github.com/minio/minio/cmd.(*erasureServerPools).BackendInfo()
      github.com/minio/minio/cmd/erasure-server-pool.go:579 +0x6f
  github.com/minio/minio/cmd.(*erasureServerPools).LocalStorageInfo()
      github.com/minio/minio/cmd/erasure-server-pool.go:614 +0x3c6
  github.com/minio/minio/cmd.(*peerRESTServer).LocalStorageInfoHandler()
      github.com/minio/minio/cmd/peer-rest-server.go:347 +0x4ea
  github.com/minio/minio/cmd.(*peerRESTServer).LocalStorageInfoHandler-fm()
```
This commit is contained in:
Klaus Post 2023-10-24 08:15:41 -07:00 committed by GitHub
parent 01b3fb91e5
commit 74253e1ddc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -228,7 +228,7 @@ func validateParity(ssParity, rrsParity, setDriveCount int) (err error) {
// //
// is returned, the caller is expected to choose the right parity // is returned, the caller is expected to choose the right parity
// at that point. // at that point.
func (sCfg Config) GetParityForSC(sc string) (parity int) { func (sCfg *Config) GetParityForSC(sc string) (parity int) {
ConfigLock.RLock() ConfigLock.RLock()
defer ConfigLock.RUnlock() defer ConfigLock.RUnlock()
switch strings.TrimSpace(sc) { switch strings.TrimSpace(sc) {