优化定时器异常recover

This commit is contained in:
boyce
2021-04-09 15:42:58 +08:00
parent 797370e146
commit 98cd055ddd

View File

@@ -2,10 +2,10 @@ package timer
import ( import (
"fmt" "fmt"
"github.com/duanhf2012/origin/log"
"github.com/duanhf2012/origin/util/sync" "github.com/duanhf2012/origin/util/sync"
"reflect" "reflect"
"runtime" "runtime"
"time" "time"
) )
@@ -90,6 +90,14 @@ type Dispatcher struct {
func (t *Timer) Do(){ func (t *Timer) Do(){
if t.cb != nil { if t.cb != nil {
defer func() {
if r := recover(); r != nil {
buf := make([]byte, 4096)
l := runtime.Stack(buf, false)
err := fmt.Errorf("%v: %s", r, buf[:l])
log.Error("core dump info:%+v\n", err)
}
}()
t.cb() t.cb()
} }
} }