Merge pull request #50550 from atlassian/cleanup-configz

Automatic merge from submit-queue (batch tested with PRs 50550, 50768)

Cleanup locking in configz

**What this PR does / why we need it**:
- Reduce scope of lock in `write()` method
- Use the read lock in `write()` method

**Release note**:
```release-note
NONE
```
/kind cleanup

@mikedanese 

p.s. looks like the `Set()` method could be removed if the value is accepted as an argument to `New()`. I.e. looks like to code re-sets the value.
pull/6/head
Kubernetes Submit Queue 2017-08-17 03:13:57 -07:00 committed by GitHub
commit a4acc38c96
1 changed files with 7 additions and 3 deletions

View File

@ -75,9 +75,13 @@ func handle(w http.ResponseWriter, r *http.Request) {
}
func write(w io.Writer) error {
configsGuard.Lock()
defer configsGuard.Unlock()
b, err := json.Marshal(configs)
var b []byte
var err error
func() {
configsGuard.RLock()
defer configsGuard.RUnlock()
b, err = json.Marshal(configs)
}()
if err != nil {
return fmt.Errorf("error marshaling json: %v", err)
}