From 855189b565902907951da0f388788e137405806f Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 2 Nov 2023 15:00:37 +0800 Subject: [PATCH] fix --- .../websocket/internal/logic/commonnotifylogic.go | 8 +------- .../internal/logic/ws_render_cancel_notify_unity.go | 13 +++---------- server/websocket/internal/logic/ws_statistics.go | 9 +-------- .../internal/logic/ws_user_connect_pool.go | 9 +-------- server/websocket/websocket.go | 12 ++++-------- 5 files changed, 10 insertions(+), 41 deletions(-) diff --git a/server/websocket/internal/logic/commonnotifylogic.go b/server/websocket/internal/logic/commonnotifylogic.go index ea961822..c64bb32d 100644 --- a/server/websocket/internal/logic/commonnotifylogic.go +++ b/server/websocket/internal/logic/commonnotifylogic.go @@ -49,18 +49,12 @@ func popCommonNotifyCache() (data commonConnectionNotFoundDataCacheChanItem) { } // 消费公共通知未处理的消息(目前是轮巡方式,待优化) -func ConsumeCommonCacheData(ctx context.Context) { +func ConsumeCommonCacheData() { defer func() { if err := recover(); err != nil { logx.Error("consumeCommonCacheData panic :", err) } }() - go func() { - select { - case <-ctx.Done(): - panic("consumeCommonCacheData ctx deadline") - } - }() for { time.Sleep(time.Millisecond * 200) info := popCommonNotifyCache() diff --git a/server/websocket/internal/logic/ws_render_cancel_notify_unity.go b/server/websocket/internal/logic/ws_render_cancel_notify_unity.go index 3bcf07b2..7aea553a 100644 --- a/server/websocket/internal/logic/ws_render_cancel_notify_unity.go +++ b/server/websocket/internal/logic/ws_render_cancel_notify_unity.go @@ -1,7 +1,6 @@ package logic import ( - "context" "crypto/md5" "encoding/hex" "encoding/json" @@ -50,14 +49,14 @@ func sendCancelRenderMsgToUnity(wid string, deadlineTime int64) { } // 拨号udp -func DialUdp(ctx context.Context, config config.Config) error { +func DialUdp(config config.Config) error { localAddr := &net.UDPAddr{IP: net.ParseIP(config.Unity.Udp.LocalAddr), Port: config.Unity.Udp.LocalPort} remoteAddr := &net.UDPAddr{IP: net.ParseIP(config.Unity.Udp.RemoteAddr), Port: config.Unity.Udp.RemotePort} conn, err := net.DialUDP("udp", localAddr, remoteAddr) if err != nil { return err } - go ConsumeCancelUnityChanMessage(ctx, conn) + go ConsumeCancelUnityChanMessage(conn) return nil } @@ -69,18 +68,12 @@ func signMessage(wid string, deadlineTime int64) string { } // 消费数据 -func ConsumeCancelUnityChanMessage(ctx context.Context, conn *net.UDPConn) { +func ConsumeCancelUnityChanMessage(conn *net.UDPConn) { defer func() { if err := recover(); err != nil { logx.Error("ConsumeCancelUnityChanMessage 异常:", err) } }() - go func() { - select { - case <-ctx.Done(): - panic(any("ConsumeCancelUnityChanMessage ctx deadline")) - } - }() defer conn.Close() for { select { diff --git a/server/websocket/internal/logic/ws_statistics.go b/server/websocket/internal/logic/ws_statistics.go index 72ce3bb8..50320398 100644 --- a/server/websocket/internal/logic/ws_statistics.go +++ b/server/websocket/internal/logic/ws_statistics.go @@ -1,7 +1,6 @@ package logic import ( - "context" "fmt" "github.com/zeromicro/go-zero/core/logx" "sync" @@ -206,18 +205,12 @@ func increaseUnityErrorCount(userId, guestId int64) { } // 消费数据 -func ConsumeWebsocketStatData(ctx context.Context) { +func ConsumeWebsocketStatData() { defer func() { if err := recover(); err != nil { logx.Error("ConsumeWebsocketStatData panic:", err) } }() - go func() { - select { - case <-ctx.Done(): - panic(any("ConsumeWebsocketStatData ctx deadline")) - } - }() for { select { case data := <-websocketStat: diff --git a/server/websocket/internal/logic/ws_user_connect_pool.go b/server/websocket/internal/logic/ws_user_connect_pool.go index d272e72e..6a63fdaa 100644 --- a/server/websocket/internal/logic/ws_user_connect_pool.go +++ b/server/websocket/internal/logic/ws_user_connect_pool.go @@ -1,7 +1,6 @@ package logic import ( - "context" "fmt" "github.com/zeromicro/go-zero/core/logx" ) @@ -56,18 +55,12 @@ func deleteUserConnPoolElement(userId, guestId int64, uniqueId string) { } // 消费用户索引创建/删除/发送消息中的任务数据 -func ConsumeUserConnPoolCtlChanData(ctx context.Context) { +func ConsumeUserConnPoolCtlChanData() { defer func() { if err := recover(); err != nil { logx.Error("ConsumeUserConnPoolCtlChanData panic:", err) } }() - go func() { - select { - case <-ctx.Done(): - panic(any("ConsumeUserConnPoolCtlChanData ctx deadline")) - } - }() var ( data userConnPoolCtlChanItem userKey string diff --git a/server/websocket/websocket.go b/server/websocket/websocket.go index 969c2c33..07fdf2e0 100644 --- a/server/websocket/websocket.go +++ b/server/websocket/websocket.go @@ -1,7 +1,6 @@ package main import ( - "context" "flag" "fmt" "fusenapi/server/websocket/internal/logic" @@ -30,17 +29,14 @@ func main() { ctx := svc.NewServiceContext(c) handler.RegisterHandlers(server, ctx) - ctx1 := context.Background() - ctx1, cancel := context.WithCancel(ctx1) - defer cancel() //消费公共通知队列的数据 - go logic.ConsumeCommonCacheData(ctx1) + go logic.ConsumeCommonCacheData() //消费用户索引创建/删除/发送消息中的任务数据 - go logic.ConsumeUserConnPoolCtlChanData(ctx1) + go logic.ConsumeUserConnPoolCtlChanData() //消费连接统计信息 - go logic.ConsumeWebsocketStatData(ctx1) + go logic.ConsumeWebsocketStatData() //拨号udp消费控制unity取消僵尸任务的消息 - if err := logic.DialUdp(ctx1, c); err != nil { + if err := logic.DialUdp(c); err != nil { logx.Error("dail udp err:", err) return }