Skip to content

Commit

Permalink
add mutex to CC stat and k8s destination
Browse files Browse the repository at this point in the history
  • Loading branch information
janusec2 committed Feb 10, 2023
1 parent 88e4539 commit c6a3a3d
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion backend/destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -68,7 +69,6 @@ func CheckOfflineDestinations(nowTimeStamp int64) {
}
dest.CheckTime = nowTimeStamp
dest.Online = true
dest.Mutex.Unlock()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion backend/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -42,7 +43,6 @@ func UpdatePods(dest *models.Destination, nowTimeStamp int64) {
dest.Pods += podItem.Status.PodIP + ":" + dest.PodPort
}
}
dest.Mutex.Unlock()
dest.IsUpdating = false
}

Expand Down
2 changes: 1 addition & 1 deletion firewall/cc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -84,7 +85,6 @@ func CCAttackTick(appID int64) {
}
stat.SlowCount += stat.QuickCount
stat.QuickCount = 0
stat.Mutex.Unlock()
return true
})
}
Expand Down
2 changes: 1 addition & 1 deletion gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c6a3a3d

Please sign in to comment.