mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #1872 from xiang90/fix_watcher_race
store: fix race in watcher_hub
This commit is contained in:
commit
6bfa5d409e
@ -33,7 +33,7 @@ import (
|
||||
// event happens between the end of the first watch command and the start
|
||||
// of the second command.
|
||||
type watcherHub struct {
|
||||
mutex sync.Mutex // protect the hash map
|
||||
mutex sync.Mutex
|
||||
watchers map[string]*list.List
|
||||
count int64 // current number of watchers.
|
||||
EventHistory *EventHistory
|
||||
@ -71,6 +71,8 @@ func (wh *watcherHub) watch(key string, recursive, stream bool, index, storeInde
|
||||
hub: wh,
|
||||
}
|
||||
|
||||
wh.mutex.Lock()
|
||||
defer wh.mutex.Unlock()
|
||||
// If the event exists in the known history, append the EtcdIndex and return immediately
|
||||
if event != nil {
|
||||
event.EtcdIndex = storeIndex
|
||||
@ -78,9 +80,6 @@ func (wh *watcherHub) watch(key string, recursive, stream bool, index, storeInde
|
||||
return w, nil
|
||||
}
|
||||
|
||||
wh.mutex.Lock()
|
||||
defer wh.mutex.Unlock()
|
||||
|
||||
l, ok := wh.watchers[key]
|
||||
|
||||
var elem *list.Element
|
||||
|
Loading…
x
Reference in New Issue
Block a user