mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #6324 from xiang90/fix_proxy_data_race
grpcproxy: fix data race
This commit is contained in:
commit
9e5bccd458
@ -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()
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user