*: fix various data races detected by race detector

This commit is contained in:
Xiang Li
2015-10-26 20:26:43 -07:00
parent 336d177c82
commit a8e6e71bf9
4 changed files with 32 additions and 2 deletions

View File

@ -22,6 +22,7 @@ import (
"reflect"
"sort"
"strings"
"sync"
"time"
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/coreos/pkg/capnslog"
@ -93,7 +94,9 @@ type store struct {
server doer
timeout time.Duration
ensuredOnce bool
enabled *bool
mu sync.Mutex // protect enabled
enabled *bool
}
type User struct {
@ -377,6 +380,9 @@ func (s *store) UpdateRole(role Role) (Role, error) {
}
func (s *store) AuthEnabled() bool {
s.mu.Lock()
defer s.mu.Unlock()
return s.detectAuth()
}
@ -384,6 +390,10 @@ func (s *store) EnableAuth() error {
if s.AuthEnabled() {
return authErr(http.StatusConflict, "already enabled")
}
s.mu.Lock()
defer s.mu.Unlock()
_, err := s.GetUser("root")
if err != nil {
return authErr(http.StatusConflict, "No root user available, please create one")
@ -412,6 +422,10 @@ func (s *store) DisableAuth() error {
if !s.AuthEnabled() {
return authErr(http.StatusConflict, "already disabled")
}
s.mu.Lock()
defer s.mu.Unlock()
err := s.disableAuth()
if err == nil {
b := false