From 60908c64a66335679884cf02f34f81af155c3ea0 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Wed, 30 Nov 2016 14:56:53 -0800 Subject: [PATCH] grpcproxy: fix race between coalesce and bcast on nextrev coalesce was locking the target coalesce broadcast object but not the source broadcast object resulting in a data race on the source's nextrev. --- proxy/grpcproxy/watch_broadcasts.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/proxy/grpcproxy/watch_broadcasts.go b/proxy/grpcproxy/watch_broadcasts.go index 81e857113..8fe9e5f51 100644 --- a/proxy/grpcproxy/watch_broadcasts.go +++ b/proxy/grpcproxy/watch_broadcasts.go @@ -59,6 +59,7 @@ func (wbs *watchBroadcasts) coalesce(wb *watchBroadcast) { if wbswb == wb { continue } + wb.mu.Lock() wbswb.mu.Lock() // 1. check if wbswb is behind wb so it won't skip any events in wb // 2. ensure wbswb started; nextrev == 0 may mean wbswb is waiting @@ -71,6 +72,7 @@ func (wbs *watchBroadcasts) coalesce(wb *watchBroadcast) { wb.receivers = nil } wbswb.mu.Unlock() + wb.mu.Unlock() if wb.empty() { delete(wbs.bcasts, wb) wb.stop()