fix(socket): 移除debug.Stack并统一使用cool.Loger记录panic错误

This commit is contained in:
1
2025-10-29 15:50:48 +00:00
parent f06638d6b6
commit 8376068bb6
4 changed files with 31 additions and 13 deletions

View File

@@ -4,7 +4,6 @@ import (
"context"
"log"
"os"
"runtime/debug"
"sync/atomic"
"time"
@@ -45,9 +44,9 @@ func (s *Server) OnClose(c gnet.Conn, _ error) (action gnet.Action) {
defer func() {
if err := recover(); err != nil { // 恢复 panicerr 为 panic 错误值
// 1. 打印错误信息
log.Printf("捕获到 panic 错误:%v", err)
// 2. 打印完整调用堆栈debug.Stack() 获取堆栈字节流,转为字符串)
log.Printf("panic 详细堆栈:\n%s", debug.Stack())
cool.Loger.Error(context.TODO(), "panic 错误:", err)
}
}()
@@ -104,9 +103,9 @@ func (s *Server) OnTraffic(c gnet.Conn) (action gnet.Action) {
defer func() {
if err := recover(); err != nil { // 恢复 panicerr 为 panic 错误值
// 1. 打印错误信息
log.Printf("捕获到 panic 错误:%v", err)
// 2. 打印完整调用堆栈debug.Stack() 获取堆栈字节流,转为字符串)
log.Printf("panic 详细堆栈:\n%s", debug.Stack())
cool.Loger.Error(context.TODO(), "panic 错误:", err)
}
}()
if s.network != "tcp" {