Skip to content

Commit

Permalink
other: 优化 server 包部分 error 的处理方式
Browse files Browse the repository at this point in the history
  • Loading branch information
kercylan98 committed Dec 20, 2023
1 parent 34a680e commit 82ecb98
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ func (slf *Server) dispatchMessage(dispatcher *dispatcher, msg *Message) {
go func(ctx context.Context, msg *Message) {
select {
case <-ctx.Done():
if err := ctx.Err(); err == context.DeadlineExceeded {
if err := ctx.Err(); errors.Is(err, context.DeadlineExceeded) {
log.Warn("Server", log.String("MessageType", messageNames[msg.t]), log.String("Info", msg.String()), log.Any("SuspectedDeadlock", msg))
slf.OnDeadlockDetectEvent(msg)
}
Expand All @@ -708,9 +708,7 @@ func (slf *Server) dispatchMessage(dispatcher *dispatcher, msg *Message) {
stack := string(debug.Stack())
log.Error("Server", log.String("MessageType", messageNames[msg.t]), log.String("Info", msg.String()), log.Any("error", err), log.String("stack", stack))
fmt.Println(stack)
if e, ok := err.(error); ok {
slf.OnMessageErrorEvent(msg, e)
}
slf.OnMessageErrorEvent(msg, fmt.Errorf("%v", err))
}
if msg.t == MessageTypeUniqueAsyncCallback || msg.t == MessageTypeUniqueShuntAsyncCallback {
dispatcher.antiUnique(msg.name)
Expand All @@ -729,7 +727,9 @@ func (slf *Server) dispatchMessage(dispatcher *dispatcher, msg *Message) {

switch msg.t {
case MessageTypePacket:
if !slf.OnConnectionPacketPreprocessEvent(msg.conn, msg.packet, func(newPacket []byte) { msg.packet = newPacket }) {
if !slf.OnConnectionPacketPreprocessEvent(msg.conn, msg.packet, func(newPacket []byte) {
msg.packet = newPacket
}) {
slf.OnConnectionReceivePacketEvent(msg.conn, msg.packet)
}
case MessageTypeError:
Expand Down

0 comments on commit 82ecb98

Please sign in to comment.