From 6c3344b12781cacfb06904a5f8f441f6ae7d7e3a Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Thu, 24 Aug 2023 14:11:17 +0800 Subject: [PATCH] fix --- server/websocket/internal/logic/datatransferlogic.go | 4 ---- server/websocket/internal/logic/ws_reuse_last_connect.go | 8 +------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index 7aedd98d..c415f075 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -64,8 +64,6 @@ var ( } //websocket连接存储 mapConnPool = sync.Map{} - //公共互斥锁(复用连接标识用) - publicMutex sync.Mutex ) // 每个连接的连接基本属性 @@ -140,8 +138,6 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request) // 设置连接 func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo auth.UserInfo, isFirefoxBrowser bool) (wsConnectItem, error) { - publicMutex.Lock() - defer publicMutex.Unlock() //生成连接唯一标识 uniqueId, err := l.getUniqueId(userInfo) if err != nil { diff --git a/server/websocket/internal/logic/ws_reuse_last_connect.go b/server/websocket/internal/logic/ws_reuse_last_connect.go index 4a328660..ddd25955 100644 --- a/server/websocket/internal/logic/ws_reuse_last_connect.go +++ b/server/websocket/internal/logic/ws_reuse_last_connect.go @@ -37,20 +37,14 @@ func (w *wsConnectItem) reuseLastConnect(data []byte) { w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR, "the client id is not belong you before")) return } - publicMutex.Lock() - defer publicMutex.Unlock() //存在是不能给他申请重新绑定 if v, ok := mapConnPool.Load(clientId); ok { obj, ok := v.(wsConnectItem) if !ok { logx.Error("连接断言失败") } - //是当前自己占用 + //是当前自己占用(无需处理) if obj.uniqueId == w.uniqueId { - //重新绑定 - w.uniqueId = clientId - rsp := w.respondDataFormat(constants.WEBSOCKET_CONNECT_SUCCESS, clientId) - w.sendToOutChan(rsp) return } else { rsp := w.respondDataFormat(constants.WEBSOCKET_REQUEST_RESUME_LAST_CONNECT_ERR, "id has bound by other connect ")