From d7a027e476130efded2005f0b381cd5b283d2978 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Wed, 9 Dec 2015 10:11:51 -0800 Subject: [PATCH] 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. --- store/watcher_hub.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/store/watcher_hub.go b/store/watcher_hub.go index d573eb331..25a701c2c 100644 --- a/store/watcher_hub.go +++ b/store/watcher_hub.go @@ -78,8 +78,9 @@ func (wh *watcherHub) watch(key string, recursive, stream bool, index, storeInde defer wh.mutex.Unlock() // If the event exists in the known history, append the EtcdIndex and return immediately if event != nil { - event.EtcdIndex = storeIndex - w.eventChan <- event + ne := event.Clone() + ne.EtcdIndex = storeIndex + w.eventChan <- ne return w, nil }