From 60a964ae55f69ebaa93eb189609327412e4837f2 Mon Sep 17 00:00:00 2001 From: Ulric Qin Date: Sun, 15 Aug 2021 10:08:08 +0800 Subject: [PATCH] bugfix: for range goroutine --- judge/prome_pull.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/judge/prome_pull.go b/judge/prome_pull.go index a5d09e63..5232e0b8 100644 --- a/judge/prome_pull.go +++ b/judge/prome_pull.go @@ -41,9 +41,9 @@ type RuleEval struct { ctx context.Context } -func (re *RuleEval) start() { - logger.Debugf("[prome_pull_alert_start][RuleEval: %+v]", re) - go func(re *RuleEval) { +func (re RuleEval) start() { + go func(re RuleEval) { + logger.Debugf("[prome_pull_alert_start][RuleEval: %+v]", re) if re.R.PullExpr.EvaluationInterval <= 0 { re.R.PullExpr.EvaluationInterval = DEFAULT_PULL_ALERT_INTERVAL } @@ -72,7 +72,7 @@ func (re *RuleEval) start() { }(re) } -func (r *RuleEval) stop() { +func (r RuleEval) stop() { logger.Debugf("[prome_pull_alert_stop][RuleEval: %+v]", r) close(r.quiteChan) } @@ -103,17 +103,17 @@ func (rm *RuleManager) SyncRules(ctx context.Context, rules []models.AlertRule) } // 停止旧的 - for hash, t := range rm.activeRules { + for hash := range rm.activeRules { if _, loaded := thisAllRules[hash]; !loaded { - t.stop() + rm.activeRules[hash].stop() delete(rm.activeRules, hash) } } rm.targetMtx.Unlock() // 开启新的 - for _, t := range thisNewRules { - t.start() + for hash := range thisNewRules { + thisNewRules[hash].start() } }