mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-08-18 18:39:51 +08:00
fix: fix incorrect kicked logic. (#3480)
* fix: fix incorrect ws check logic. * optimize checkSameToken logic.
This commit is contained in:
parent
3ad24d9521
commit
097e033347
@ -249,6 +249,7 @@ func (s *Server) MultiTerminalLoginCheck(ctx context.Context, req *msggateway.Mu
|
|||||||
tempUserCtx.SetOperationID(mcontext.GetOperationID(ctx))
|
tempUserCtx.SetOperationID(mcontext.GetOperationID(ctx))
|
||||||
client := &Client{}
|
client := &Client{}
|
||||||
client.ctx = tempUserCtx
|
client.ctx = tempUserCtx
|
||||||
|
client.token = req.Token
|
||||||
client.UserID = req.UserID
|
client.UserID = req.UserID
|
||||||
client.PlatformID = int(req.PlatformID)
|
client.PlatformID = int(req.PlatformID)
|
||||||
i := &kickHandler{
|
i := &kickHandler{
|
||||||
|
@ -334,6 +334,27 @@ func (ws *WsServer) multiTerminalLoginChecker(clientOK bool, oldClients []*Clien
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If reconnect: When multiple msgGateway instances are deployed, a client may disconnect from instance A and reconnect to instance B.
|
||||||
|
// During this process, instance A might still be executing, resulting in two clients with the same token existing simultaneously.
|
||||||
|
// This situation needs to be filtered to prevent duplicate clients.
|
||||||
|
checkSameTokenFunc := func(oldClients []*Client) []*Client {
|
||||||
|
var clientsNeedToKick []*Client
|
||||||
|
|
||||||
|
for _, c := range oldClients {
|
||||||
|
if c.token == newClient.token {
|
||||||
|
log.ZDebug(newClient.ctx, "token is same, not kick",
|
||||||
|
"userID", newClient.UserID,
|
||||||
|
"platformID", newClient.PlatformID,
|
||||||
|
"token", newClient.token)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
clientsNeedToKick = append(clientsNeedToKick, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
return clientsNeedToKick
|
||||||
|
}
|
||||||
|
|
||||||
switch ws.msgGatewayConfig.Share.MultiLogin.Policy {
|
switch ws.msgGatewayConfig.Share.MultiLogin.Policy {
|
||||||
case constant.DefalutNotKick:
|
case constant.DefalutNotKick:
|
||||||
case constant.PCAndOther:
|
case constant.PCAndOther:
|
||||||
@ -349,11 +370,15 @@ func (ws *WsServer) multiTerminalLoginChecker(clientOK bool, oldClients []*Clien
|
|||||||
}
|
}
|
||||||
oldClients = append(oldClients, c)
|
oldClients = append(oldClients, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
fallthrough
|
fallthrough
|
||||||
case constant.AllLoginButSameTermKick:
|
case constant.AllLoginButSameTermKick:
|
||||||
if !clientOK {
|
if !clientOK {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
oldClients = checkSameTokenFunc(oldClients)
|
||||||
|
|
||||||
ws.clients.DeleteClients(newClient.UserID, oldClients)
|
ws.clients.DeleteClients(newClient.UserID, oldClients)
|
||||||
for _, c := range oldClients {
|
for _, c := range oldClients {
|
||||||
err := c.KickOnlineMessage()
|
err := c.KickOnlineMessage()
|
||||||
@ -361,6 +386,7 @@ func (ws *WsServer) multiTerminalLoginChecker(clientOK bool, oldClients []*Clien
|
|||||||
log.ZWarn(c.ctx, "KickOnlineMessage", err)
|
log.ZWarn(c.ctx, "KickOnlineMessage", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := mcontext.WithMustInfoCtx(
|
ctx := mcontext.WithMustInfoCtx(
|
||||||
[]string{newClient.ctx.GetOperationID(), newClient.ctx.GetUserID(),
|
[]string{newClient.ctx.GetOperationID(), newClient.ctx.GetUserID(),
|
||||||
constant.PlatformIDToName(newClient.PlatformID), newClient.ctx.GetConnID()},
|
constant.PlatformIDToName(newClient.PlatformID), newClient.ctx.GetConnID()},
|
||||||
@ -379,14 +405,17 @@ func (ws *WsServer) multiTerminalLoginChecker(clientOK bool, oldClients []*Clien
|
|||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var (
|
|
||||||
kickClients []*Client
|
var kickClients []*Client
|
||||||
)
|
|
||||||
for _, client := range clients {
|
for _, client := range clients {
|
||||||
if constant.PlatformIDToClass(client.PlatformID) == constant.PlatformIDToClass(newClient.PlatformID) {
|
if constant.PlatformIDToClass(client.PlatformID) == constant.PlatformIDToClass(newClient.PlatformID) {
|
||||||
|
{
|
||||||
kickClients = append(kickClients, client)
|
kickClients = append(kickClients, client)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
kickClients = checkSameTokenFunc(kickClients)
|
||||||
|
|
||||||
kickTokenFunc(kickClients)
|
kickTokenFunc(kickClients)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user