fix bug :KickUserOffline panic: runtime error: invalid memory address or nil pointer dereference

pull/351/head
skiffer-git 2 years ago
parent 93cb01e7e6
commit db8763b610

@ -323,7 +323,7 @@ func (r *RPCServer) KickUserOffline(_ context.Context, req *pbRelay.KickUserOffl
oldConnMap := ws.getUserAllCons(v)
if conn, ok := oldConnMap[int(req.PlatformID)]; ok { // user->map[platform->conn]
log.NewWarn(req.OperationID, "send kick msg, close connection ", req.PlatformID, v)
ws.sendKickMsg(conn, &UserConn{})
ws.sendKickMsg(conn)
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 oldConn, ok := oldConnMap[platformID]; ok {
log.NewDebug(operationID, uid, platformID, "kick old conn")
ws.sendKickMsg(oldConn, newConn)
ws.sendKickMsg(oldConn)
m, err := db.DB.GetTokenMapByUidPid(uid, constant.PlatformIDToName(platformID))
if err != nil && err != go_redis.Nil {
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:
}
}
func (ws *WServer) sendKickMsg(oldConn, newConn *UserConn) {
func (ws *WServer) sendKickMsg(oldConn *UserConn) {
mReply := Resp{
ReqIdentifier: constant.WSKickOnlineMsg,
ErrCode: constant.ErrTokenInvalid.ErrCode,
@ -273,12 +273,12 @@ func (ws *WServer) sendKickMsg(oldConn, newConn *UserConn) {
enc := gob.NewEncoder(&b)
err := enc.Encode(mReply)
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
}
err = ws.writeMsg(oldConn, websocket.BinaryMessage, b.Bytes())
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
if err := createMongoIndex(mongoClient, cSendLog, false, "send_id", "-send_time"); err != nil {
fmt.Println("send_id", "-send_time", "index create failed", err.Error())
panic(err.Error())
}
if err := createMongoIndex(mongoClient, cChat, true, "uid"); err != nil {
fmt.Println("uid", " index create failed", err.Error())
panic(err.Error())
}
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())
panic(err.Error())
}
if err := createMongoIndex(mongoClient, cWorkMoment, true, "work_moment_id"); err != nil {
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 {
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 {
fmt.Println("user_id", "-create_time", "index create failed", err.Error())
panic(err.Error())
}
if err := createMongoIndex(mongoClient, cTag, true, "tag_id"); err != nil {
fmt.Println("tag_id", "index create failed", err.Error())
panic(err.Error())
}
fmt.Println("createMongoIndex success")
DB.mongoClient = mongoClient

Loading…
Cancel
Save