AlexStocks / getty

a netty like asynchronous network I/O library based on tcp/udp/websocket; a bidirectional RPC framework based on JSON/Protobuf; a microservice framework based on zookeeper/etcd
Apache License 2.0
888 stars 186 forks source link

attention:session handleTcpPackage() blocked when Getty session taskpool is nil #39

Open dk-lockdown opened 4 years ago

dk-lockdown commented 4 years ago

If you r going to wait response,or block the goroutine in a getty session(tcp conection), task pool can not be null。

func (s *Server) newSession(session getty.Session) error {
    var (
        ok      bool
        tcpConn *net.TCPConn
    )

    // 省略部分代码...
    session.SetTaskPool(srvGrpool)
    return nil
}

ortherwise,handleTcpPackage() will blocked,led to the response missing

func (s *session) addTask(pkg interface{}) {
    f := func() {
        s.listener.OnMessage(s, pkg)
        s.incReadPkgNum()
    }
    if s.tPool != nil {
        s.tPool.AddTask(f)
        return
    }
    f()
}
AlexStocks commented 4 years ago

image 这种情况啊,第一你用我的task pool,但是最终还是受限于 gxsync.TaskPoolOptions {tQLen, tQNumber, tQPoolSize}; 第二,不用我的task pool,在你的 OnMessage 中快速调用 go,也能实现同样的 业务和网络处理分离,分离参数你自己控制。

dk-lockdown commented 3 years ago

image 这种情况啊,第一你用我的task pool,但是最终还是受限于 gxsync.TaskPoolOptions {tQLen, tQNumber, tQPoolSize}; 第二,不用我的task pool,在你的 OnMessage 中快速调用 go,也能实现同样的 业务和网络处理分离,分离参数你自己控制。

这个 taskpool 还有一个问题,add 的 task 方法,需要一个兜底的 defer 去解决 panic,如果没有这个兜底的 defer 的话,task 方法 panic 后,进入 gxruntime.GoSafely 的 defer,执行完这个 goroutine 就关闭了,然后这个 taskpool 就会再加 task 的话,会加到 p.qArray[i] 某个 chan,这个 chan 永远没有 goroutine 去消费他的 task。