diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index cab7f28e..82b1bb74 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -93,7 +93,6 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request) logx.Error("http upgrade websocket err:", err) return } - defer conn.Close() //鉴权不成功后断开 var ( userInfo *auth.UserInfo @@ -103,11 +102,13 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request) if !isAuth { //未授权响应消息 l.unAuthResponse(conn) + conn.Close() return } //设置连接 ws, err := l.setConnPool(conn, *userInfo) if err != nil { + conn.Close() return } defer ws.close() @@ -249,7 +250,6 @@ func (w *wsConnectItem) heartbeat() { //发送心跳信息 if err := w.conn.WriteMessage(websocket.PongMessage, nil); err != nil { logx.Error("发送心跳信息异常,关闭连接:", w.uniqueId, err) - w.close() return } }