Cleanup locking in configz

- Reduce scope of lock in write() method
- User read lock in write() method
This commit is contained in:
Mikhail Mazurskiy 2017-08-12 17:24:32 +10:00
parent c1da492ad2
commit 7e7a811717
No known key found for this signature in database
GPG Key ID: 93551ECC96E2F568

View File

@ -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)
} }