From 07ea51ecb599b5fda7f9881c00641c6c15766ddb Mon Sep 17 00:00:00 2001 From: Anshul Pundir Date: Thu, 6 Sep 2018 17:33:51 -0700 Subject: [PATCH] [manager/dispatcher] Fix deadlock in dispatcher shutdown. Signed-off-by: Anshul Pundir --- manager/dispatcher/dispatcher.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/manager/dispatcher/dispatcher.go b/manager/dispatcher/dispatcher.go index d783fd4c35..ca61dce109 100644 --- a/manager/dispatcher/dispatcher.go +++ b/manager/dispatcher/dispatcher.go @@ -342,6 +342,13 @@ func (d *Dispatcher) Stop() error { d.cancel() d.mu.Unlock() + d.processUpdatesLock.Lock() + // In case there are any waiters. There is no chance of any starting + // after this point, because they check if the context is canceled + // before waiting. + d.processUpdatesCond.Broadcast() + d.processUpdatesLock.Unlock() + // The active nodes list can be cleaned out only when all // existing RPCs have finished. // RPCs that start after rpcRW.Unlock() should find the context @@ -351,13 +358,6 @@ func (d *Dispatcher) Stop() error { d.downNodes.Clean() d.rpcRW.Unlock() - d.processUpdatesLock.Lock() - // In case there are any waiters. There is no chance of any starting - // after this point, because they check if the context is canceled - // before waiting. - d.processUpdatesCond.Broadcast() - d.processUpdatesLock.Unlock() - d.clusterUpdateQueue.Close() // TODO(anshul): This use of Wait() could be unsafe.