Browse Source

grpcproxy: fix deadlock in watchbroadcast

Calling empty() in watchbroadcast methods was trying to
lock the rwmutex when it was already held.

Fixes #6937
Anthony Romano 9 years ago
parent
commit
91ff6f30b5
1 changed files with 3 additions and 3 deletions
  1. 3 3
      proxy/grpcproxy/watch_broadcast.go

+ 3 - 3
proxy/grpcproxy/watch_broadcast.go

@@ -89,8 +89,8 @@ func (wb *watchBroadcast) bcast(wr clientv3.WatchResponse) {
 	for r := range wb.receivers {
 	for r := range wb.receivers {
 		r.send(wr)
 		r.send(wr)
 	}
 	}
-	if wb.size() > 0 {
-		eventsCoalescing.Add(float64(wb.size() - 1))
+	if len(wb.receivers) > 0 {
+		eventsCoalescing.Add(float64(len(wb.receivers) - 1))
 	}
 	}
 }
 }
 
 
@@ -135,7 +135,7 @@ func (wb *watchBroadcast) delete(w *watcher) {
 		panic("deleting missing watcher from broadcast")
 		panic("deleting missing watcher from broadcast")
 	}
 	}
 	delete(wb.receivers, w)
 	delete(wb.receivers, w)
-	if !wb.empty() {
+	if len(wb.receivers) > 0 {
 		// do not dec the only left watcher for coalescing.
 		// do not dec the only left watcher for coalescing.
 		watchersCoalescing.Dec()
 		watchersCoalescing.Dec()
 	}
 	}