From 3c42814b5885b0ae10631c6a8a66b858c7923380 Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> Date: Thu, 21 Jul 2022 17:15:10 +0500 Subject: [PATCH] avoid deadlock --- weed/server/master_server.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/weed/server/master_server.go b/weed/server/master_server.go index 03a3f74d1..6c0b6652b 100644 --- a/weed/server/master_server.go +++ b/weed/server/master_server.go @@ -368,8 +368,16 @@ func (ms *MasterServer) OnPeerUpdate(update *master_pb.ClusterNodeUpdate, startF } } ms.onPeerUpdateLock.RLock() - if len(ms.onPeerUpdateDoneCns) > 0 { - for _, onPeerUpdateDoneCn := range ms.onPeerUpdateDoneCns { + isGtZero := len(ms.onPeerUpdateDoneCns) > 0 + ms.onPeerUpdateLock.RUnlock() + if isGtZero { + var chanPtrs []*chan string + ms.onPeerUpdateLock.RLock() + for _, cn := range ms.onPeerUpdateDoneCns { + chanPtrs = append(chanPtrs, cn) + } + ms.onPeerUpdateLock.RUnlock() + for _, onPeerUpdateDoneCn := range chanPtrs { *onPeerUpdateDoneCn <- peerName } }