mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-25 02:58:26 +08:00
fix bug :KickUserOffline panic: runtime error: invalid memory address or nil pointer dereference
This commit is contained in:
parent
93cb01e7e6
commit
db8763b610
@ -323,7 +323,7 @@ func (r *RPCServer) KickUserOffline(_ context.Context, req *pbRelay.KickUserOffl
|
|||||||
oldConnMap := ws.getUserAllCons(v)
|
oldConnMap := ws.getUserAllCons(v)
|
||||||
if conn, ok := oldConnMap[int(req.PlatformID)]; ok { // user->map[platform->conn]
|
if conn, ok := oldConnMap[int(req.PlatformID)]; ok { // user->map[platform->conn]
|
||||||
log.NewWarn(req.OperationID, "send kick msg, close connection ", req.PlatformID, v)
|
log.NewWarn(req.OperationID, "send kick msg, close connection ", req.PlatformID, v)
|
||||||
ws.sendKickMsg(conn, &UserConn{})
|
ws.sendKickMsg(conn)
|
||||||
conn.Close()
|
conn.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -214,7 +214,7 @@ func (ws *WServer) MultiTerminalLoginChecker(uid string, platformID int, newConn
|
|||||||
if oldConnMap, ok := ws.wsUserToConn[uid]; ok { // user->map[platform->conn]
|
if oldConnMap, ok := ws.wsUserToConn[uid]; ok { // user->map[platform->conn]
|
||||||
if oldConn, ok := oldConnMap[platformID]; ok {
|
if oldConn, ok := oldConnMap[platformID]; ok {
|
||||||
log.NewDebug(operationID, uid, platformID, "kick old conn")
|
log.NewDebug(operationID, uid, platformID, "kick old conn")
|
||||||
ws.sendKickMsg(oldConn, newConn)
|
ws.sendKickMsg(oldConn)
|
||||||
m, err := db.DB.GetTokenMapByUidPid(uid, constant.PlatformIDToName(platformID))
|
m, err := db.DB.GetTokenMapByUidPid(uid, constant.PlatformIDToName(platformID))
|
||||||
if err != nil && err != go_redis.Nil {
|
if err != nil && err != go_redis.Nil {
|
||||||
log.NewError(operationID, "get token from redis err", err.Error(), uid, constant.PlatformIDToName(platformID))
|
log.NewError(operationID, "get token from redis err", err.Error(), uid, constant.PlatformIDToName(platformID))
|
||||||
@ -263,7 +263,7 @@ func (ws *WServer) MultiTerminalLoginChecker(uid string, platformID int, newConn
|
|||||||
case constant.WebAndOther:
|
case constant.WebAndOther:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (ws *WServer) sendKickMsg(oldConn, newConn *UserConn) {
|
func (ws *WServer) sendKickMsg(oldConn *UserConn) {
|
||||||
mReply := Resp{
|
mReply := Resp{
|
||||||
ReqIdentifier: constant.WSKickOnlineMsg,
|
ReqIdentifier: constant.WSKickOnlineMsg,
|
||||||
ErrCode: constant.ErrTokenInvalid.ErrCode,
|
ErrCode: constant.ErrTokenInvalid.ErrCode,
|
||||||
@ -273,12 +273,12 @@ func (ws *WServer) sendKickMsg(oldConn, newConn *UserConn) {
|
|||||||
enc := gob.NewEncoder(&b)
|
enc := gob.NewEncoder(&b)
|
||||||
err := enc.Encode(mReply)
|
err := enc.Encode(mReply)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(mReply.OperationID, mReply.ReqIdentifier, mReply.ErrCode, mReply.ErrMsg, "Encode Msg error", oldConn.RemoteAddr().String(), newConn.RemoteAddr().String(), err.Error())
|
log.NewError(mReply.OperationID, mReply.ReqIdentifier, mReply.ErrCode, mReply.ErrMsg, "Encode Msg error", oldConn.RemoteAddr().String(), err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = ws.writeMsg(oldConn, websocket.BinaryMessage, b.Bytes())
|
err = ws.writeMsg(oldConn, websocket.BinaryMessage, b.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(mReply.OperationID, mReply.ReqIdentifier, mReply.ErrCode, mReply.ErrMsg, "sendKickMsg WS WriteMsg error", oldConn.RemoteAddr().String(), newConn.RemoteAddr().String(), err.Error())
|
log.NewError(mReply.OperationID, mReply.ReqIdentifier, mReply.ErrCode, mReply.ErrMsg, "sendKickMsg WS WriteMsg error", oldConn.RemoteAddr().String(), err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,24 +96,31 @@ func init() {
|
|||||||
// mongodb create index
|
// mongodb create index
|
||||||
if err := createMongoIndex(mongoClient, cSendLog, false, "send_id", "-send_time"); err != nil {
|
if err := createMongoIndex(mongoClient, cSendLog, false, "send_id", "-send_time"); err != nil {
|
||||||
fmt.Println("send_id", "-send_time", "index create failed", err.Error())
|
fmt.Println("send_id", "-send_time", "index create failed", err.Error())
|
||||||
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
if err := createMongoIndex(mongoClient, cChat, true, "uid"); err != nil {
|
if err := createMongoIndex(mongoClient, cChat, true, "uid"); err != nil {
|
||||||
fmt.Println("uid", " index create failed", err.Error())
|
fmt.Println("uid", " index create failed", err.Error())
|
||||||
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
if err := createMongoIndex(mongoClient, cWorkMoment, true, "-create_time", "work_moment_id"); err != nil {
|
if err := createMongoIndex(mongoClient, cWorkMoment, true, "-create_time", "work_moment_id"); err != nil {
|
||||||
fmt.Println("-create_time", "work_moment_id", "index create failed", err.Error())
|
fmt.Println("-create_time", "work_moment_id", "index create failed", err.Error())
|
||||||
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
if err := createMongoIndex(mongoClient, cWorkMoment, true, "work_moment_id"); err != nil {
|
if err := createMongoIndex(mongoClient, cWorkMoment, true, "work_moment_id"); err != nil {
|
||||||
fmt.Println("work_moment_id", "index create failed", err.Error())
|
fmt.Println("work_moment_id", "index create failed", err.Error())
|
||||||
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
if err := createMongoIndex(mongoClient, cWorkMoment, false, "user_id", "-create_time"); err != nil {
|
if err := createMongoIndex(mongoClient, cWorkMoment, false, "user_id", "-create_time"); err != nil {
|
||||||
fmt.Println("user_id", "-create_time", "index create failed", err.Error())
|
fmt.Println("user_id", "-create_time", "index create failed", err.Error())
|
||||||
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
if err := createMongoIndex(mongoClient, cTag, false, "user_id", "-create_time"); err != nil {
|
if err := createMongoIndex(mongoClient, cTag, false, "user_id", "-create_time"); err != nil {
|
||||||
fmt.Println("user_id", "-create_time", "index create failed", err.Error())
|
fmt.Println("user_id", "-create_time", "index create failed", err.Error())
|
||||||
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
if err := createMongoIndex(mongoClient, cTag, true, "tag_id"); err != nil {
|
if err := createMongoIndex(mongoClient, cTag, true, "tag_id"); err != nil {
|
||||||
fmt.Println("tag_id", "index create failed", err.Error())
|
fmt.Println("tag_id", "index create failed", err.Error())
|
||||||
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
fmt.Println("createMongoIndex success")
|
fmt.Println("createMongoIndex success")
|
||||||
DB.mongoClient = mongoClient
|
DB.mongoClient = mongoClient
|
||||||
|
Loading…
x
Reference in New Issue
Block a user