From f3f1de99611bd063c676b23fdd738a39f04f10de Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 22 Aug 2023 18:22:27 +0800 Subject: [PATCH 1/9] fix --- server/websocket/internal/logic/ws_render_image_logic.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index f3e09ecd..b14f8972 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -389,6 +389,10 @@ func (w *wsConnectItem) deleteRenderTask(data renderImageControlChanItem) { // 修改耗时属性(只有耗时属性可以更新) func (w *wsConnectItem) modifyRenderTaskTimeConsuming(data renderImageControlChanItem) { + if data.TaskId == "" { + logx.Error("设置耗时属性需要的task_id不能为空") + return + } //强制设为修改耗时属性 data.Option = 2 select { From 0fab87065baa14ab84e941ae7bacd66684c31774 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 22 Aug 2023 18:24:24 +0800 Subject: [PATCH 2/9] fix --- server/websocket/internal/logic/ws_render_image_logic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index b14f8972..757a5164 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -405,7 +405,7 @@ func (w *wsConnectItem) modifyRenderTaskTimeConsuming(data renderImageControlCha } } -// 操作连接中渲染任务的增加/删除(任务map不能读写并发,所以放在chan里面串行执行) +// 处理渲染任务的增加/删除/修改耗时属性(任务map不能读写并发,所以放在chan里面串行执行) func (w *wsConnectItem) operationRenderTask() { for { select { From 7682843f3eb98ca021d76a03e3b0394a9a520f45 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 22 Aug 2023 18:31:25 +0800 Subject: [PATCH 3/9] fix --- .../internal/logic/datatransferlogic.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 3ded3810..ef830380 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -205,7 +205,7 @@ func (l *DataTransferLogic) unAuthResponse(conn *websocket.Conn) { conn.Close() } -// 心跳 +// 心跳检测 func (w *wsConnectItem) heartbeat() { tick := time.Tick(time.Second * 5) for { @@ -223,7 +223,7 @@ func (w *wsConnectItem) heartbeat() { } } -// 关闭连接 +// 关闭websocket连接 func (w *wsConnectItem) close() { w.mutex.Lock() defer w.mutex.Unlock() @@ -239,7 +239,7 @@ func (w *wsConnectItem) close() { logx.Info("websocket:", w.uniqueId, " is closed") } -// 读取输出返回给客户端 +// 读取出口缓冲池数据输出返回给浏览器端 func (w *wsConnectItem) writeLoop() { for { select { @@ -255,7 +255,7 @@ func (w *wsConnectItem) writeLoop() { } } -// 接受客户端发来的消息 +// 接受客户端发来的消息并写入入口缓冲池 func (w *wsConnectItem) readLoop() { for { select { @@ -278,7 +278,7 @@ func (w *wsConnectItem) readLoop() { } } -// 把收到的消息发往不同的地方处理 +// 消费websocket入口数据池中的数据 func (w *wsConnectItem) sendLoop() { for { select { @@ -290,7 +290,7 @@ func (w *wsConnectItem) sendLoop() { } } -// 把要传递给客户端的数据放入outchan +// 把要传递给客户端的数据放入出口缓冲池 func (w *wsConnectItem) sendToOutChan(data []byte) { select { case <-w.closeChan: @@ -302,7 +302,7 @@ func (w *wsConnectItem) sendToOutChan(data []byte) { } } -// 格式化返回数据 +// 格式化为websocket标准返回格式 func (w *wsConnectItem) respondDataFormat(msgType string, data interface{}) []byte { d := websocket_data.DataTransferData{ T: msgType, @@ -312,7 +312,7 @@ func (w *wsConnectItem) respondDataFormat(msgType string, data interface{}) []by return b } -// 处理接受到的数据 +// 处理入口缓冲池中不同类型的数据(分发处理) func (w *wsConnectItem) dealwithReciveData(data []byte) { var parseInfo websocket_data.DataTransferData if err := json.Unmarshal(data, &parseInfo); err != nil { From 3e7b4e9c4b22f078cd3a1ff35c456a0209c180df Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Tue, 22 Aug 2023 18:37:49 +0800 Subject: [PATCH 4/9] fix --- .../internal/logic/datatransferlogic.go | 20 +++++++++++++++++++ .../internal/logic/ws_render_image_logic.go | 15 +++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index ef830380..a19675ee 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -146,6 +146,11 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo auth.User //保存连接 mapConnPool.Store(uniqueId, ws) go func() { + defer func() { + if err := recover(); err != nil { + logx.Error("set conn pool panic:", err) + } + }() //把连接成功消息发回去 time.Sleep(time.Second * 1) //兼容下火狐(直接发回去收不到第一条消息:有待研究) ws.sendToOutChan(ws.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, uniqueId)) @@ -241,6 +246,11 @@ func (w *wsConnectItem) close() { // 读取出口缓冲池数据输出返回给浏览器端 func (w *wsConnectItem) writeLoop() { + defer func() { + if err := recover(); err != nil { + logx.Error("write loop panic:", err) + } + }() for { select { case <-w.closeChan: //如果关闭了 @@ -257,6 +267,11 @@ func (w *wsConnectItem) writeLoop() { // 接受客户端发来的消息并写入入口缓冲池 func (w *wsConnectItem) readLoop() { + defer func() { + if err := recover(); err != nil { + logx.Error("read loop panic:", err) + } + }() for { select { case <-w.closeChan: //如果关闭了 @@ -280,6 +295,11 @@ func (w *wsConnectItem) readLoop() { // 消费websocket入口数据池中的数据 func (w *wsConnectItem) sendLoop() { + defer func() { + if err := recover(); err != nil { + logx.Error("send loop panic:", err) + } + }() for { select { case <-w.closeChan: diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index 757a5164..7ace49f9 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -72,6 +72,11 @@ func (w *wsConnectItem) renderImage() { // 消费渲染缓冲数据 func (w *wsConnectItem) consumeRenderCache(data []byte) { + defer func() { + if err := recover(); err != nil { + logx.Error("consumeRenderCache panic:", err) + } + }() logx.Info("消费渲染数据:", string(data)) var renderImageData websocket_data.RenderImageReqMsg if err := json.Unmarshal(data, &renderImageData); err != nil { @@ -164,11 +169,6 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) { // 组装数据发送给unity func (w *wsConnectItem) assembleRenderData(taskId string, info websocket_data.RenderImageReqMsg) error { - defer func() { - if err := recover(); err != nil { - logx.Error("assembleRenderData panic:", err) - } - }() //获取产品第一个尺寸 productFirstSize, err := w.logic.svcCtx.AllModels.FsProductSize.GetProductFirstSize(w.logic.ctx, info.RenderData.ProductId) if err != nil { @@ -407,6 +407,11 @@ func (w *wsConnectItem) modifyRenderTaskTimeConsuming(data renderImageControlCha // 处理渲染任务的增加/删除/修改耗时属性(任务map不能读写并发,所以放在chan里面串行执行) func (w *wsConnectItem) operationRenderTask() { + defer func() { + if err := recover(); err != nil { + logx.Error("operation render task panic:", err) + } + }() for { select { case <-w.closeChan: From 0a635e5113e8e34f1c86eb24deab09d3903ceae5 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 23 Aug 2023 10:06:17 +0800 Subject: [PATCH 5/9] fix --- server/websocket/internal/logic/ws_render_image_logic.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index 7ace49f9..7ffe0418 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -138,6 +138,7 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) { resource, err := w.logic.svcCtx.AllModels.FsResource.FindOneById(w.logic.ctx, taskId) if err != nil { if !errors.Is(err, gorm.ErrRecordNotFound) { + w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE_ERR, fmt.Sprintf("获取云渲染缓存资源错误 task_id:%s ", taskId))) logx.Error("failed to find render resource:", err) return } From d7ff6f24c22cbb9c935189a4bbf78cc795e0a528 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 23 Aug 2023 10:39:23 +0800 Subject: [PATCH 6/9] fix --- server/websocket/internal/logic/ws_render_image_logic.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index 7ffe0418..abe7c290 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -118,6 +118,7 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) { w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "failed to get default logo")) return } + logx.Info("##########:", userMaterialDefault) renderImageData.RenderData.Logo = *userMaterialDefault.ResourceUrl } else { renderImageData.RenderData.Logo = *userMaterial.ResourceUrl From 79b06c6c7de87f0d515fb66f3a95513e77e1ca61 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 23 Aug 2023 10:42:09 +0800 Subject: [PATCH 7/9] fix --- server/websocket/internal/logic/ws_render_image_logic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index abe7c290..a2af7e67 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -118,7 +118,6 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) { w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "failed to get default logo")) return } - logx.Info("##########:", userMaterialDefault) renderImageData.RenderData.Logo = *userMaterialDefault.ResourceUrl } else { renderImageData.RenderData.Logo = *userMaterial.ResourceUrl @@ -144,6 +143,7 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) { return } } else { + logx.Info("#############:", resource) //返回给客户端 b := w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{ RenderId: renderImageData.RenderId, From d5f33433c317699c9c17fd6015669adcb43f4152 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 23 Aug 2023 10:49:54 +0800 Subject: [PATCH 8/9] fix --- server/websocket/internal/logic/ws_render_image_logic.go | 1 - 1 file changed, 1 deletion(-) diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index a2af7e67..7ffe0418 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -143,7 +143,6 @@ func (w *wsConnectItem) consumeRenderCache(data []byte) { return } } else { - logx.Info("#############:", resource) //返回给客户端 b := w.respondDataFormat(constants.WEBSOCKET_RENDER_IMAGE, websocket_data.RenderImageRspMsg{ RenderId: renderImageData.RenderId, From 3593d32fb34dcfc1a54417aa265da37e8439ab32 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Wed, 23 Aug 2023 11:03:45 +0800 Subject: [PATCH 9/9] fix --- server/websocket/internal/logic/ws_render_image_logic.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/server/websocket/internal/logic/ws_render_image_logic.go b/server/websocket/internal/logic/ws_render_image_logic.go index 7ffe0418..d9af03d2 100644 --- a/server/websocket/internal/logic/ws_render_image_logic.go +++ b/server/websocket/internal/logic/ws_render_image_logic.go @@ -72,11 +72,6 @@ func (w *wsConnectItem) renderImage() { // 消费渲染缓冲数据 func (w *wsConnectItem) consumeRenderCache(data []byte) { - defer func() { - if err := recover(); err != nil { - logx.Error("consumeRenderCache panic:", err) - } - }() logx.Info("消费渲染数据:", string(data)) var renderImageData websocket_data.RenderImageReqMsg if err := json.Unmarshal(data, &renderImageData); err != nil {