fix(master): Set the cluster's stop channel to nil upon receiving the signal to prevent it from running again

Signed-off-by: leonrayang <chl696@sina.com>
This commit is contained in:
leonrayang 2024-10-08 11:46:08 +08:00 committed by chihe
parent 1594864cb1
commit 39b2d22679
2 changed files with 6 additions and 0 deletions

View File

@ -108,6 +108,7 @@ type Cluster struct {
MasterSecretKey []byte
retainLogs uint64
stopc chan bool
stopFlag int32
wg sync.WaitGroup
ClusterVolSubItem

View File

@ -23,6 +23,7 @@ import (
"regexp"
"strconv"
"sync"
"sync/atomic"
"time"
"github.com/cubefs/cubefs/proto"
@ -190,6 +191,10 @@ func (m *Server) Start(cfg *config.Config) (err error) {
// Shutdown closes the server
func (m *Server) Shutdown() {
var err error
if !atomic.CompareAndSwapInt32(&m.cluster.stopFlag, 0, 1) {
log.LogWarnf("action[Shutdown] cluster already stopped!")
return
}
if m.cluster.stopc != nil {
close(m.cluster.stopc)
m.cluster.wg.Wait()