1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-03-17 21:07:54 +02:00

Merge pull request #155 from kevwan/ticker_leak

avoid ticker leak when cpustat.ReadStat(...) panic
This commit is contained in:
Terry.Mao 2019-06-13 01:10:32 -05:00 committed by GitHub
commit 257d42b23c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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{}