Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dk-lockdown opened this issue Apr 26, 2020 · 2 comments

Comments

@dk-lockdown
Copy link

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
Copy link
Owner

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

@dk-lockdown
Copy link
Author

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。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants