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] 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: