Unverified Commit 39a57011 authored by Wesley Liddick's avatar Wesley Liddick Committed by GitHub
Browse files

Merge pull request #1182 from DaydreamCoding/fix/ops-alert-wg-race-and-context-leak

fix(ops_alert): wg.Add 竞态修复 + leader lock release context 泄漏
parents a225a241 5c39e6f2
...@@ -88,6 +88,7 @@ func (s *OpsAlertEvaluatorService) Start() { ...@@ -88,6 +88,7 @@ func (s *OpsAlertEvaluatorService) Start() {
if s.stopCh == nil { if s.stopCh == nil {
s.stopCh = make(chan struct{}) s.stopCh = make(chan struct{})
} }
s.wg.Add(1)
go s.run() go s.run()
}) })
} }
...@@ -105,7 +106,6 @@ func (s *OpsAlertEvaluatorService) Stop() { ...@@ -105,7 +106,6 @@ func (s *OpsAlertEvaluatorService) Stop() {
} }
func (s *OpsAlertEvaluatorService) run() { func (s *OpsAlertEvaluatorService) run() {
s.wg.Add(1)
defer s.wg.Done() defer s.wg.Done()
// Start immediately to produce early feedback in ops dashboard. // Start immediately to produce early feedback in ops dashboard.
...@@ -848,7 +848,9 @@ func (s *OpsAlertEvaluatorService) tryAcquireLeaderLock(ctx context.Context, loc ...@@ -848,7 +848,9 @@ func (s *OpsAlertEvaluatorService) tryAcquireLeaderLock(ctx context.Context, loc
return nil, false return nil, false
} }
return func() { return func() {
_, _ = opsAlertEvaluatorReleaseScript.Run(ctx, s.redisClient, []string{key}, s.instanceID).Result() releaseCtx, releaseCancel := context.WithTimeout(context.Background(), 5*time.Second)
defer releaseCancel()
_, _ = opsAlertEvaluatorReleaseScript.Run(releaseCtx, s.redisClient, []string{key}, s.instanceID).Result()
}, true }, true
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment