修复ksync.go崩溃时获得崩溃特征码有可能并发崩溃问题lastAttributeCode
This commit is contained in:
parent
1de3a11c56
commit
9a6a73cae5
@ -5,29 +5,28 @@ import (
|
||||
"github.com/fox/fox/log"
|
||||
"github.com/wanghuiyt/ding"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 辅助函数列表
|
||||
var (
|
||||
DingAccessToken = "" // 钉钉token
|
||||
DingSecret = "" // 钉钉加签
|
||||
lastAttributeCode = "" // 最近一条error信息
|
||||
//lastAttributeCode = "" // 最近一条error信息
|
||||
)
|
||||
|
||||
func getAttributeCode(stackErr string) string {
|
||||
lines := strings.Split(stackErr, "\n")
|
||||
// 检查是否有足够的行数,并提取第9行(索引为8,因为索引从0开始)
|
||||
if len(lines) >= 9 {
|
||||
goIndex := strings.LastIndex(lines[8], ".go")
|
||||
if goIndex != -1 {
|
||||
filteredStr := lines[8][:goIndex]
|
||||
filteredStr = strings.TrimLeft(filteredStr, "\t ")
|
||||
return filteredStr
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
//func getAttributeCode(stackErr string) string {
|
||||
// lines := strings.Split(stackErr, "\n")
|
||||
// // 检查是否有足够的行数,并提取第9行(索引为8,因为索引从0开始)
|
||||
// if len(lines) >= 9 {
|
||||
// goIndex := strings.LastIndex(lines[8], ".go")
|
||||
// if goIndex != -1 {
|
||||
// filteredStr := lines[8][:goIndex]
|
||||
// filteredStr = strings.TrimLeft(filteredStr, "\t ")
|
||||
// return filteredStr
|
||||
// }
|
||||
// }
|
||||
// return ""
|
||||
//}
|
||||
|
||||
// 发送消息给钉钉
|
||||
func sendMessage(msg interface{}, stackErr string, dingToken, dingSecret string) {
|
||||
@ -43,13 +42,13 @@ func sendMessage(msg interface{}, stackErr string, dingToken, dingSecret string)
|
||||
func Recover(recoverFunc func()) {
|
||||
if msg := recover(); msg != nil {
|
||||
stackErr := string(debug.Stack())
|
||||
attributeCode := getAttributeCode(stackErr)
|
||||
if lastAttributeCode != attributeCode {
|
||||
lastAttributeCode = attributeCode
|
||||
//attributeCode := getAttributeCode(stackErr)
|
||||
//if lastAttributeCode != attributeCode {
|
||||
// lastAttributeCode = attributeCode
|
||||
log.ErrorF("Recover panic:%v", msg)
|
||||
log.Error(stackErr)
|
||||
sendMessage(msg, stackErr, DingAccessToken, DingSecret)
|
||||
}
|
||||
//}
|
||||
if recoverFunc != nil {
|
||||
recoverFunc()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user