lonng / nano

Lightweight, facility, high performance golang based game server framework
MIT License
2.88k stars 445 forks source link

关于不同节点调用传递的sessionId,为什么多节点的session 对象不直接使用同一个sessionId进行匹配? #110

Closed novel045 closed 9 months ago

novel045 commented 9 months ago

Question

传递的sessionId在当前节点找不到的时候, 新增会话对象同时当前的会话对象又使用新的sessionId,但是又使用旧的sessionid 进行节点会话池注册,这个是处于什么考虑呢?
func (n *Node) findOrCreateSession(sid int64, gateAddr string) (*session.Session, error) {
    n.mu.RLock()
    s, found := n.sessions[sid]
    n.mu.RUnlock()
    if !found {
        conns, err := n.rpcClient.getConnPool(gateAddr)
        if err != nil {
            return nil, err
        }
        ac := &acceptor{
            sid:        sid,
            gateClient: clusterpb.NewMemberClient(conns.Get()),
            rpcHandler: n.handler.remoteProcess,
            gateAddr:   gateAddr,
        }
        s = session.New(ac)
        ac.session = s
        n.mu.Lock()
        n.sessions[sid] = s
        n.mu.Unlock()
    }
    return s, nil
}