From b562da5c3776ef6bc42658a1d090bd577c434f1f Mon Sep 17 00:00:00 2001 From: Gordon <46924906+FGadvancer@users.noreply.github.com> Date: Wed, 8 Nov 2023 18:17:09 +0800 Subject: [PATCH] fix: sync close ws conn when kick old user avoid wrong trigger order about online status. (#1368) --- internal/msggateway/client.go | 4 +++- internal/msggateway/n_ws_server.go | 7 +------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/internal/msggateway/client.go b/internal/msggateway/client.go index b32130c9a..9eeac3835 100644 --- a/internal/msggateway/client.go +++ b/internal/msggateway/client.go @@ -297,7 +297,9 @@ func (c *Client) KickOnlineMessage() error { resp := Resp{ ReqIdentifier: WSKickOnlineMsg, } - return c.writeBinaryMsg(resp) + err := c.writeBinaryMsg(resp) + c.close() + return err } func (c *Client) writeBinaryMsg(resp Resp) error { diff --git a/internal/msggateway/n_ws_server.go b/internal/msggateway/n_ws_server.go index ad56c1373..c58710e1b 100644 --- a/internal/msggateway/n_ws_server.go +++ b/internal/msggateway/n_ws_server.go @@ -225,12 +225,7 @@ func (ws *WsServer) registerClient(client *Client) { ws.onlineUserNum.Add(1) ws.onlineUserConnNum.Add(1) } else { - i := &kickHandler{ - clientOK: clientOK, - oldClients: oldClients, - newClient: client, - } - ws.kickHandlerChan <- i + ws.multiTerminalLoginChecker(clientOK, oldClients, client) log.ZDebug(client.ctx, "user exist", "userID", client.UserID, "platformID", client.PlatformID) if clientOK { ws.clients.Set(client.UserID, client)