test-errcode
Gordon 2 years ago
parent 4c18e47e96
commit 3239dfe0a0

@ -18,6 +18,7 @@ import (
var ErrConnClosed = errors.New("conn has closed")
var ErrNotSupportMessageProtocol = errors.New("not support message protocol")
var ErrClientClosed = errors.New("client actively close the connection")
var ErrPanic = errors.New("panic error")
const (
// MessageText is for UTF-8 encoded text messages like JSON.
@ -82,6 +83,7 @@ func (c *Client) pongHandler(_ string) error {
func (c *Client) readMessage() {
defer func() {
if r := recover(); r != nil {
c.closedErr = ErrPanic
fmt.Println("socket have panic err:", r, string(debug.Stack()))
}
c.close()
@ -95,7 +97,7 @@ func (c *Client) readMessage() {
c.closedErr = returnErr
return
}
log.ZDebug(c.ctx, "readMessage", "messageType", messageType, "message", string(message))
log.ZDebug(c.ctx, "readMessage", "messageType", messageType)
if c.closed == true { //连接刚置位已经关闭,但是协程还没退出的场景
c.closedErr = ErrConnClosed
return

Loading…
Cancel
Save