diff --git a/backend/destination.go b/backend/destination.go index 76ad6e4..44f4288 100644 --- a/backend/destination.go +++ b/backend/destination.go @@ -57,6 +57,7 @@ func CheckOfflineDestinations(nowTimeStamp int64) { utils.DebugPrintln("Unmarshal K8S API", err) } dest.Mutex.Lock() + defer dest.Mutex.Unlock() dest.Pods = "" for _, podItem := range pods.Items { if podItem.Status.Phase == "Running" { @@ -68,7 +69,6 @@ func CheckOfflineDestinations(nowTimeStamp int64) { } dest.CheckTime = nowTimeStamp dest.Online = true - dest.Mutex.Unlock() } } } diff --git a/backend/k8s.go b/backend/k8s.go index 91d5bcf..b52f51d 100644 --- a/backend/k8s.go +++ b/backend/k8s.go @@ -20,6 +20,7 @@ import ( func UpdatePods(dest *models.Destination, nowTimeStamp int64) { dest.IsUpdating = true dest.Mutex.Lock() // write lock + defer dest.Mutex.Unlock() request, _ := http.NewRequest("GET", dest.PodsAPI, nil) request.Header.Set("Content-Type", "application/json") resp, err := utils.GetResponse(request) @@ -42,7 +43,6 @@ func UpdatePods(dest *models.Destination, nowTimeStamp int64) { dest.Pods += podItem.Status.PodIP + ":" + dest.PodPort } } - dest.Mutex.Unlock() dest.IsUpdating = false } diff --git a/firewall/cc.go b/firewall/cc.go index 787783e..3408e94 100644 --- a/firewall/cc.go +++ b/firewall/cc.go @@ -54,6 +54,7 @@ func CCAttackTick(appID int64) { stat := value.(*models.ClientStat) //fmt.Println("CCAttackTick:", appID, clientID, stat) stat.Mutex.Lock() + defer stat.Mutex.Unlock() if stat.IsBadIP { stat.RemainSeconds -= ccPolicy.IntervalMilliSeconds / 1000.0 if stat.RemainSeconds <= 0 { @@ -84,7 +85,6 @@ func CCAttackTick(appID int64) { } stat.SlowCount += stat.QuickCount stat.QuickCount = 0 - stat.Mutex.Unlock() return true }) } diff --git a/gateway/gateway.go b/gateway/gateway.go index 69cba41..fc8c3c0 100644 --- a/gateway/gateway.go +++ b/gateway/gateway.go @@ -389,8 +389,8 @@ func ReverseHandlerFunc(w http.ResponseWriter, r *http.Request) { dest.CheckTime = nowTimeStamp if err != nil { dest.Mutex.Lock() + defer dest.Mutex.Unlock() dest.Online = false - dest.Mutex.Unlock() utils.DebugPrintln("DialContext error", err) if data.NodeSetting.SMTP.SMTPEnabled { sendOfflineNotification(app, targetDest)