diff --git a/internal/interaction/long_conn_mgr.go b/internal/interaction/long_conn_mgr.go index 4f09b9340..9b96dddef 100644 --- a/internal/interaction/long_conn_mgr.go +++ b/internal/interaction/long_conn_mgr.go @@ -21,6 +21,7 @@ import ( "fmt" "io" "runtime" + "runtime/debug" "strconv" "strings" "sync" @@ -175,6 +176,13 @@ func (c *LongConnMgr) SendReqWaitResp(ctx context.Context, m proto.Message, reqI // reads from this goroutine. func (c *LongConnMgr) readPump(ctx context.Context) { + defer func() { + if r := recover(); r != nil { + err := fmt.Sprintf("panic: %+v\n%s", r, debug.Stack()) + log.ZError(ctx, "readPump panic", errs.New(err)) + } + }() + log.ZDebug(ctx, "readPump start", "goroutine ID:", getGoroutineID()) defer func() { _ = c.close() @@ -233,6 +241,12 @@ func (c *LongConnMgr) readPump(ctx context.Context) { // application ensures that there is at most one writer to a connection by // executing all writes from this goroutine. func (c *LongConnMgr) writePump(ctx context.Context) { + defer func() { + if r := recover(); r != nil { + err := fmt.Sprintf("panic: %+v\n%s", r, debug.Stack()) + log.ZError(ctx, "writePump panic", errs.New(err)) + } + }() log.ZDebug(ctx, "writePump start", "goroutine ID:", getGoroutineID()) defer func() { @@ -282,6 +296,13 @@ func (c *LongConnMgr) writePump(ctx context.Context) { } func (c *LongConnMgr) heartbeat(ctx context.Context) { + defer func() { + if r := recover(); r != nil { + err := fmt.Sprintf("panic: %+v\n%s", r, debug.Stack()) + log.ZError(ctx, "heartbeat panic", errs.New(err)) + } + }() + log.ZDebug(ctx, "heartbeat start", "goroutine ID:", getGoroutineID()) ticker := time.NewTicker(pingPeriod) defer func() { diff --git a/internal/interaction/msg_sync.go b/internal/interaction/msg_sync.go index 47a4a024a..e4e956eb0 100644 --- a/internal/interaction/msg_sync.go +++ b/internal/interaction/msg_sync.go @@ -16,6 +16,8 @@ package interaction import ( "context" + "fmt" + "runtime/debug" "strings" "sync" @@ -149,6 +151,12 @@ func (m *MsgSyncer) loadSeq(ctx context.Context) error { // DoListener Listen to the message pipe of the message synchronizer // and process received and pushed messages func (m *MsgSyncer) DoListener(ctx context.Context) { + defer func() { + if r := recover(); r != nil { + err := fmt.Sprintf("panic: %+v\n%s", r, debug.Stack()) + log.ZError(ctx, "DoListener panic", errs.New(err)) + } + }() for { select { case cmd := <-m.PushMsgAndMaxSeqCh: diff --git a/open_im_sdk/userRelated.go b/open_im_sdk/userRelated.go index 3b99de5df..534ef7512 100644 --- a/open_im_sdk/userRelated.go +++ b/open_im_sdk/userRelated.go @@ -18,12 +18,14 @@ import ( "context" "encoding/json" "fmt" - "github.com/openimsdk/openim-sdk-core/v3/internal/flagconst" + "runtime/debug" "strings" "sync" "time" "unsafe" + "github.com/openimsdk/openim-sdk-core/v3/internal/flagconst" + "github.com/openimsdk/openim-sdk-core/v3/internal/business" conv "github.com/openimsdk/openim-sdk-core/v3/internal/conversation_msg" "github.com/openimsdk/openim-sdk-core/v3/internal/file" @@ -248,6 +250,13 @@ func (u *LoginMgr) GetLoginUserID() string { return u.loginUserID } func (u *LoginMgr) logoutListener(ctx context.Context) { + defer func() { + if r := recover(); r != nil { + err := fmt.Sprintf("panic: %+v\n%s", r, debug.Stack()) + log.ZError(ctx, "logoutListener panic", errs.New(err)) + } + }() + for { select { case <-u.loginMgrCh: diff --git a/pkg/common/trigger_channel.go b/pkg/common/trigger_channel.go index aee5e4734..0c052e849 100644 --- a/pkg/common/trigger_channel.go +++ b/pkg/common/trigger_channel.go @@ -17,6 +17,8 @@ package common import ( "context" "errors" + "fmt" + "runtime/debug" "time" "github.com/openimsdk/openim-sdk-core/v3/pkg/constant" @@ -209,6 +211,13 @@ type goroutine interface { } func DoListener(Li goroutine, ctx context.Context) { + defer func() { + if r := recover(); r != nil { + err := fmt.Sprintf("panic: %+v\n%s", r, debug.Stack()) + log.ZError(ctx, "DoListener panic", errs.New(err)) + } + }() + for { select { case cmd := <-Li.GetCh():