From b94e5ecd9f7710d4d63e3f33e6352a54706e2d8c Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 13 Jun 2019 13:21:23 +0800 Subject: [PATCH] avoid ticker leak when cpustat.ReadStat(...) panic --- pkg/ratelimit/bbr/bbr.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/ratelimit/bbr/bbr.go b/pkg/ratelimit/bbr/bbr.go index 2d5cb9e97..fe153d52f 100644 --- a/pkg/ratelimit/bbr/bbr.go +++ b/pkg/ratelimit/bbr/bbr.go @@ -32,13 +32,15 @@ func init() { } func cpuproc() { + ticker := time.NewTicker(time.Millisecond * 250) defer func() { + ticker.Stop() if err := recover(); err != nil { log.Error("rate.limit.cpuproc() err(%+v)", err) go cpuproc() } }() - ticker := time.NewTicker(time.Millisecond * 250) + // EMA algorithm: https://blog.csdn.net/m0_38106113/article/details/81542863 for range ticker.C { stat := &cpustat.Stat{}