Selaa lähdekoodia

etcdserver: remove a data race of ServerStat

It seems that ServerStats.BecomeLeader() is missing a lock.

Fix https://github.com/coreos/etcd/issues/5155
Hitoshi Mitake 9 vuotta sitten
vanhempi
commit
24077fb3f6
1 muutettua tiedostoa jossa 3 lisäystä ja 0 poistoa
  1. 3 0
      etcdserver/stats/server.go

+ 3 - 0
etcdserver/stats/server.go

@@ -142,6 +142,9 @@ func (ss *ServerStats) SendAppendReq(reqSize int) {
 }
 
 func (ss *ServerStats) BecomeLeader() {
+	ss.Lock()
+	defer ss.Unlock()
+
 	if ss.State != raft.StateLeader {
 		ss.State = raft.StateLeader
 		ss.LeaderInfo.Name = ss.ID