Commit a4acc38c authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

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.
parents 402e48b0 7e7a8117
...@@ -75,9 +75,13 @@ func handle(w http.ResponseWriter, r *http.Request) { ...@@ -75,9 +75,13 @@ func handle(w http.ResponseWriter, r *http.Request) {
} }
func write(w io.Writer) error { func write(w io.Writer) error {
configsGuard.Lock() var b []byte
defer configsGuard.Unlock() var err error
b, err := json.Marshal(configs) func() {
configsGuard.RLock()
defer configsGuard.RUnlock()
b, err = json.Marshal(configs)
}()
if err != nil { if err != nil {
return fmt.Errorf("error marshaling json: %v", err) return fmt.Errorf("error marshaling json: %v", err)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment