奇怪panic问题

线上服务器出现崩溃,但是显示崩溃点有点奇怪 异常如下:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x78 pc=0x9bc10a]

goroutine 10459 [running]:
panic(0xacc0c0, 0xfd0b50)
        C:/Go/src/runtime/panic.go:551 +0x3c1 fp=0xc42136b440 sp=0xc42136b3a0 pc=0x42a411
runtime.panicmem()
        C:/Go/src/runtime/panic.go:63 +0x5e fp=0xc42136b460 sp=0xc42136b440 pc=0x4292ee
runtime.sigpanic()
        C:/Go/src/runtime/signal_unix.go:388 +0x17a fp=0xc42136b4b0 sp=0xc42136b460 pc=0x44008a
main.RunKey(...)
        D:/go/xmmorpg_svn/mvdzs_h5/server/src/center/run.go:152
main.ReplaceRoleRunInfo(0xc420894000, 0xc42122f280, 0xe24900000002, 0xc42287f0e0, 0x20)
        D:/go/xmmorpg_svn/mvdzs_h5/server/src/center/run.go:331 +0x1ba fp=0xc42136b920 sp=0xc42136b4b0 pc=0x9bc10a
main.EnterGameReq(0xc4210402d0, 0xc400000002, 0xc423d71770)
        D:/go/xmmorpg_svn/mvdzs_h5/server/src/center/x_login_mgr.go:74 +0x8ec fp=0xc42136bfc8 sp=0xc42136b920 pc=0x9dac3c
runtime.goexit()
        C:/Go/src/runtime/asm_amd64.s:2361 +0x1 fp=0xc42136bfd0 sp=0xc42136bfc8 pc=0x459a81

代码如下:

func RunKey(gateID uint32, connId uint32) uint64 {
    return uint64(gateID)<<32 | uint64(connId)
}
func ReplaceRoleRunInfo(rr *RoleRunInfo, rd *redis.Client, gateID uint32, connId uint32, token string) {
    rr.Token = token

    _gateConnMapMutex.Lock()
    delete(GateConnRRMap, RunKey(rr.Session().ServerID, rr.ConnId))
    GateConnRRMap[RunKey(gateID, connId)] = rr
    _gateConnMapMutex.Unlock()

    rr.DisconnectClient()
    rr.GateId = gateID
    rr.ConnId = connId

}

RunKey这个函数里面为什么能触发panic,这个真的想不通

已邀请:

sheepbao - https://sheepbao.github.io 爱go,爱编程,领域网络开发,流媒体、分布式、网络加速

赞同来自:

你是 delete(GateConnRRMap, RunKey(rr.Session().ServerID, rr.ConnId))这行, rr为nil,或者 rr.Session() 结果为nil吧?我猜的,go里面整型溢出是不会panic的

yhf_szb - 攻城狮

赞同来自:

这种bug最好先把嵌套的语句全部拆成单句,要不很那判断具体出错的地方。

例如:

key := RunKey(gateID, connId)
GateConnRRMap[key] = rr

另外你的panic是带行号的,你代码里没有行号……看不出是哪……

要回复问题请先登录注册