```
fix(socket): 异步处理连接关闭逻辑 将连接关闭时的数据保存和资源清理操作提交到工作池中异步执行, 避免阻塞主线程。但需要注意可能存在执行顺序问题,需要进一步修复。 ```
This commit is contained in:
@@ -54,17 +54,20 @@ func (s *Server) OnClose(c gnet.Conn, _ error) (action gnet.Action) {
|
||||
atomic.AddInt64(&s.connected, -1)
|
||||
//logging.Infof("conn[%v] disconnected", c.RemoteAddr().String())
|
||||
v, _ := c.Context().(*player.ClientData)
|
||||
v.Lf.Close() //关闭lockfree
|
||||
s.workerPool.Submit(func() { //TODO 这里可能存在顺序执行问题,待修复
|
||||
v.Lf.Close() //关闭lockfree
|
||||
|
||||
if v.Player != nil {
|
||||
//cool.Loger.Info(context.TODO(), "准备保存", v.Player.Info.UserID)
|
||||
v.Player.Save() //保存玩家数据
|
||||
//cool.Loger.Info(context.TODO(), "保存完成", v.Player.Info.UserID)
|
||||
if v.CloseChan != nil {
|
||||
close(v.CloseChan)
|
||||
}
|
||||
|
||||
if v.Player != nil {
|
||||
//cool.Loger.Info(context.TODO(), "准备保存", v.Player.Info.UserID)
|
||||
v.Player.Save() //保存玩家数据
|
||||
//cool.Loger.Info(context.TODO(), "保存完成", v.Player.Info.UserID)
|
||||
if v.CloseChan != nil {
|
||||
close(v.CloseChan)
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
//}
|
||||
//关闭连接
|
||||
|
||||
Reference in New Issue
Block a user