Browse Source

clientv3: fix race on writing watch channel over return channel

Found in TestElectionFailover
Anthony Romano 9 years ago
parent
commit
4bdfc0a46d
1 changed files with 3 additions and 3 deletions
  1. 3 3
      clientv3/watch.go

+ 3 - 3
clientv3/watch.go

@@ -240,11 +240,11 @@ func (w *watcher) addStream(resp *pb.WatchResponse, pendingReq *watchRequest) {
 	w.streams[ws.id] = ws
 	w.mu.Unlock()
 
-	// send messages to subscriber
-	go w.serveStream(ws)
-
 	// pass back the subscriber channel for the watcher
 	pendingReq.retc <- ret
+
+	// send messages to subscriber
+	go w.serveStream(ws)
 }
 
 // closeStream closes the watcher resources and removes it