From d349fe3197d027ccd874fda629516bd76eeebd27 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 23 Aug 2023 18:16:12 +0800 Subject: [PATCH 1/3] fix --- server/websocket/internal/logic/loginnotifylogic.go | 4 ++++ server/websocket/internal/logic/registeraccountnotifylogic.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/server/websocket/internal/logic/loginnotifylogic.go b/server/websocket/internal/logic/loginnotifylogic.go index a532764e..024880a4 100644 --- a/server/websocket/internal/logic/loginnotifylogic.go +++ b/server/websocket/internal/logic/loginnotifylogic.go @@ -46,11 +46,13 @@ func (l *LoginNotifyLogic) LoginNotify(req *types.LoginNotifyReq, userinfo *auth logx.Error("解密失败:", err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ") } + //真正的数据结构 var parseInfo websocket_data.NotifyData if err = json.Unmarshal([]byte(data), &parseInfo); err != nil { logx.Error("failed to parse json data:", err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid format of parse data") } + //websocket连接id不能为空 if parseInfo.WebsocketConnectId == "" { return resp.SetStatusWithMessage(basic.CodeServiceErr, "websocket connect id is empty") } @@ -59,10 +61,12 @@ func (l *LoginNotifyLogic) LoginNotify(req *types.LoginNotifyReq, userinfo *auth if parseInfo.RequestTime < now-20 || parseInfo.RequestTime > now+20 { return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ,time is not in allowed range") } + //查询websocket连接 value, ok := mapConnPool.Load(parseInfo.WebsocketConnectId) if !ok { return resp.SetStatusWithMessage(basic.CodeOK, "success,but connection is not found") } + //断言连接 ws, ok := value.(wsConnectItem) if !ok { logx.Error("渲染回调断言websocket连接失败") diff --git a/server/websocket/internal/logic/registeraccountnotifylogic.go b/server/websocket/internal/logic/registeraccountnotifylogic.go index 278c2a13..74da6240 100644 --- a/server/websocket/internal/logic/registeraccountnotifylogic.go +++ b/server/websocket/internal/logic/registeraccountnotifylogic.go @@ -46,11 +46,13 @@ func (l *RegisterAccountNotifyLogic) RegisterAccountNotify(req *types.RegisterAc logx.Error("解密失败:", err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ") } + //真正的数据结构 var parseInfo websocket_data.NotifyData if err = json.Unmarshal([]byte(data), &parseInfo); err != nil { logx.Error("failed to parse json data:", err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid format of parse data") } + //websocket连接id不能为空 if parseInfo.WebsocketConnectId == "" { return resp.SetStatusWithMessage(basic.CodeServiceErr, "websocket connect id is empty") } @@ -59,10 +61,12 @@ func (l *RegisterAccountNotifyLogic) RegisterAccountNotify(req *types.RegisterAc if parseInfo.RequestTime < now-20 || parseInfo.RequestTime > now+20 { return resp.SetStatusWithMessage(basic.CodeServiceErr, "invalid data ,time is not in allowed range") } + //查询websocket连接 value, ok := mapConnPool.Load(parseInfo.WebsocketConnectId) if !ok { return resp.SetStatusWithMessage(basic.CodeOK, "success,but connection is not found") } + //断言连接 ws, ok := value.(wsConnectItem) if !ok { logx.Error("渲染回调断言websocket连接失败") From 41909b7defa290ebf506066e568cb3f3b3ff91bb Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 23 Aug 2023 18:18:44 +0800 Subject: [PATCH 2/3] fix --- server/websocket/internal/logic/rendernotifylogic.go | 2 +- server/websocket/internal/logic/ws_render_image_logic.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/websocket/internal/logic/rendernotifylogic.go b/server/websocket/internal/logic/rendernotifylogic.go index 9b6ff45a..89405427 100644 --- a/server/websocket/internal/logic/rendernotifylogic.go +++ b/server/websocket/internal/logic/rendernotifylogic.go @@ -88,7 +88,7 @@ func (l *RenderNotifyLogic) RenderNotify(req *types.RenderNotifyReq, userinfo *a }) //发送处理并删除任务 ws.deleteRenderTask(renderImageControlChanItem{ - Option: 0, //0删除 1添加 + Option: 0, //0删除 1添加 2修改耗时属性 TaskId: req.TaskId, RenderNotifyImageUrl: uploadRes.ResourceUrl, }) diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index 1a4587e5..dc9b3b46 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -154,7 +154,7 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) { //########################################### //把需要渲染的图片任务加进去 w.createRenderTask(renderImageControlChanItem{ - Option: 1, //0删除 1添加 + Option: 1, //0删除 1添加 2修改耗时属性 TaskId: taskId, RenderId: renderImageData.RenderId, }) From 810949c9d860de88ac9bb6785eb7d2d36067b483 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 23 Aug 2023 18:34:01 +0800 Subject: [PATCH 3/3] fix --- server/websocket/internal/logic/datatransferlogic.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 } }