feat: server.Server 在执行 Shutdown 时将会等待所有消息分发器被释放

This commit is contained in:
kercylan98 2024-01-12 18:33:33 +08:00
parent e760ef2a0f
commit 4f2850b355
1 changed files with 22 additions and 1 deletions

View File

@ -191,7 +191,7 @@ func (srv *Server) shutdown(err error) {
var infoCount int
for srv.messageCounter.Load() > 0 {
if infoCount%10 == 0 {
if infoCount%10 == 0 || infoCount == 0 {
log.Info("Server",
log.Any("network", srv.network),
log.String("listen", srv.addr),
@ -202,7 +202,28 @@ func (srv *Server) shutdown(err error) {
time.Sleep(time.Second)
infoCount++
}
dispatcherMgrStopSignal := make(chan struct{})
go func(srv *Server, c <-chan struct{}) {
var infoCount int
for {
select {
case <-c:
return
case <-time.After(time.Second):
if infoCount%10 == 0 || infoCount == 0 {
log.Info("Server",
log.Any("network", srv.network),
log.String("listen", srv.addr),
log.String("action", "shutdown"),
log.String("state", "waiting"),
log.Int64("dispatcher", srv.dispatcherMgr.GetDispatcherNum()))
}
infoCount++
}
}
}(srv, dispatcherMgrStopSignal)
srv.dispatcherMgr.Wait()
close(dispatcherMgrStopSignal)
if srv.multiple == nil {
srv.OnStopEvent()
}