store: fix data race when modify event in watchHub.
The event got from watchHub should be considered as readonly. To modify it, we first need to get a clone of it or there might be a data race.release-2.3
parent
5a4a5998a3
commit
d7a027e476
|
@ -78,8 +78,9 @@ func (wh *watcherHub) watch(key string, recursive, stream bool, index, storeInde
|
||||||
defer wh.mutex.Unlock()
|
defer wh.mutex.Unlock()
|
||||||
// If the event exists in the known history, append the EtcdIndex and return immediately
|
// If the event exists in the known history, append the EtcdIndex and return immediately
|
||||||
if event != nil {
|
if event != nil {
|
||||||
event.EtcdIndex = storeIndex
|
ne := event.Clone()
|
||||||
w.eventChan <- event
|
ne.EtcdIndex = storeIndex
|
||||||
|
w.eventChan <- ne
|
||||||
return w, nil
|
return w, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue