Merge pull request #6324 from xiang90/fix_proxy_data_race

grpcproxy: fix data race
This commit is contained in:
Xiang Li 2016-08-31 18:48:51 -07:00 committed by GitHub
commit 9e5bccd458
2 changed files with 18 additions and 1 deletions

View File

@ -86,9 +86,23 @@ type serverWatchStream struct {
func (sws *serverWatchStream) close() {
close(sws.watchCh)
close(sws.ctrlCh)
var wg sync.WaitGroup
sws.mu.Lock()
for _, ws := range sws.singles {
wg.Add(1)
ws.stop()
// copy the range variable to avoid race
copyws := ws
go func() {
<-copyws.stopNotify()
wg.Done()
}()
}
sws.mu.Unlock()
wg.Wait()
sws.groups.stop()
}

View File

@ -70,5 +70,8 @@ func (ws watcherSingle) canPromote() bool {
func (ws watcherSingle) stop() {
ws.cancel()
<-ws.donec
}
func (ws watcherSingle) stopNotify() <-chan struct{} {
return ws.donec
}