Merge pull request #6906 from heyitsanthony/fix-watchclose-race

grpcproxy: fix race between watch ranges delete() and broadcasts empty()
This commit is contained in:
Anthony Romano
2016-11-28 16:26:03 -08:00
committed by GitHub
2 changed files with 4 additions and 5 deletions

View File

@@ -96,7 +96,8 @@ func (wbs *watchBroadcasts) add(w *watcher) {
wbs.bcasts[wb] = struct{}{}
}
func (wbs *watchBroadcasts) delete(w *watcher) {
// delete removes a watcher and returns the number of remaining watchers.
func (wbs *watchBroadcasts) delete(w *watcher) int {
wbs.mu.Lock()
defer wbs.mu.Unlock()
@@ -110,10 +111,9 @@ func (wbs *watchBroadcasts) delete(w *watcher) {
delete(wbs.bcasts, wb)
wb.stop()
}
return len(wbs.bcasts)
}
func (wbs *watchBroadcasts) empty() bool { return len(wbs.bcasts) == 0 }
func (wbs *watchBroadcasts) stop() {
wbs.mu.Lock()
for wb := range wbs.bcasts {

View File

@@ -53,8 +53,7 @@ func (wrs *watchRanges) delete(w *watcher) {
if !ok {
panic("deleting missing range")
}
wbs.delete(w)
if wbs.empty() {
if wbs.delete(w) == 0 {
wbs.stop()
delete(wrs.bcasts, w.wr)
}