From 3c67c5fd59705d49470ab87ad4cd0783469158db Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Tue, 30 Jan 2024 17:19:36 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20ws=E5=90=8C=E7=BB=84=E5=A4=9A?= =?UTF-8?q?=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/ws/service/ws.impl.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/modules/ws/service/ws.impl.go b/src/modules/ws/service/ws.impl.go index 447438b0..36409894 100644 --- a/src/modules/ws/service/ws.impl.go +++ b/src/modules/ws/service/ws.impl.go @@ -85,7 +85,17 @@ func (s *WSImpl) NewClient(uid string, groupIDs []string, conn *websocket.Conn) for _, groupID := range groupIDs { if v, ok := WsGroup.Load(groupID); ok { groupUIDs := v.(*[]string) - *groupUIDs = append(*groupUIDs, uid) + // 避免同组内相同用户 + hasUid := false + for _, uidv := range *groupUIDs { + if uidv == uid { + hasUid = true + break + } + } + if !hasUid { + *groupUIDs = append(*groupUIDs, uid) + } } else { WsGroup.Store(groupID, &[]string{uid}) } @@ -145,6 +155,7 @@ func (s *WSImpl) clientWrite(wsClient *model.WSClient) { s.CloseClient(wsClient.ID) return } + wsClient.LastHeartbeat = time.Now().UnixMilli() } } From 3554fc341db1420ca804f4555be2dc7ad19de220 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Tue, 30 Jan 2024 17:20:25 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=20ws=E6=B6=88=E6=81=AF=E6=97=A0?= =?UTF-8?q?=E6=B6=88=E8=B4=B9chan=E6=BA=A2=E5=87=BA=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/ws/service/ws_send.impl.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/ws/service/ws_send.impl.go b/src/modules/ws/service/ws_send.impl.go index 62b7601a..8db8fcd9 100644 --- a/src/modules/ws/service/ws_send.impl.go +++ b/src/modules/ws/service/ws_send.impl.go @@ -41,6 +41,10 @@ func (s *WSSendImpl) ByClientID(clientID string, data any) error { } client := v.(*model.WSClient) + if len(client.MsgChan) > 90 { + NewWSImpl.CloseClient(client.ID) + return fmt.Errorf("msg chan over 90 will close client ID: %s", clientID) + } client.MsgChan <- dataByte return nil }