From 4d4cd0948d45bc537cbc2eaf3babca0559d27b25 Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> Date: Fri, 12 Aug 2022 01:03:26 +0300 Subject: [PATCH] avoid infinite loop WaitUntilConnected() (#3431) https://github.com/seaweedfs/seaweedfs/issues/3421 --- weed/server/master_server.go | 4 +--- weed/wdclient/masterclient.go | 8 ++++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/weed/server/master_server.go b/weed/server/master_server.go index 57103f166..fbc27e610 100644 --- a/weed/server/master_server.go +++ b/weed/server/master_server.go @@ -276,11 +276,9 @@ func (ms *MasterServer) startAdminScripts() { go commandEnv.MasterClient.KeepConnectedToMaster() go func() { - commandEnv.MasterClient.WaitUntilConnected() - for { time.Sleep(time.Duration(sleepMinutes) * time.Minute) - if ms.Topo.IsLeader() { + if ms.Topo.IsLeader() && ms.MasterClient.GetMaster() != "" { shellOptions.FilerAddress = ms.GetOneFiler(cluster.FilerGroupName(*shellOptions.FilerGroup)) if shellOptions.FilerAddress == "" { continue diff --git a/weed/wdclient/masterclient.go b/weed/wdclient/masterclient.go index 8b361aa67..391dd9199 100644 --- a/weed/wdclient/masterclient.go +++ b/weed/wdclient/masterclient.go @@ -93,7 +93,10 @@ func (mc *MasterClient) GetMasters() map[string]pb.ServerAddress { } func (mc *MasterClient) WaitUntilConnected() { - for mc.currentMaster == "" { + for { + if mc.currentMaster != "" { + return + } time.Sleep(time.Duration(rand.Int31n(200)) * time.Millisecond) } } @@ -135,7 +138,6 @@ func (mc *MasterClient) FindLeaderFromOtherPeers(myMasterAddress pb.ServerAddres func (mc *MasterClient) tryAllMasters() { var nextHintedLeader pb.ServerAddress for _, master := range mc.masters { - nextHintedLeader = mc.tryConnectToMaster(master) for nextHintedLeader != "" { nextHintedLeader = mc.tryConnectToMaster(nextHintedLeader) @@ -228,9 +230,7 @@ func (mc *MasterClient) tryConnectToMaster(master pb.ServerAddress) (nextHintedL } } } - } - }) if gprcErr != nil { stats.MasterClientConnectCounter.WithLabelValues(stats.Failed).Inc()