Skip to content

Commit

Permalink
fix: 修复 server 包连接断开消息分发器阻塞的问题,优化等待消息时打印的日志频率
Browse files Browse the repository at this point in the history
  • Loading branch information
kercylan98 committed Jan 12, 2024
1 parent 6f78684 commit af23744
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 2 additions & 3 deletions server/internal/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (d *Dispatcher[P, M]) Expel() {
func (d *Dispatcher[P, M]) noLockExpel() {
d.expel = true
if d.mc <= 0 {
d.abort <- struct{}{}
close(d.abort)
}
}

Expand All @@ -139,7 +139,7 @@ func (d *Dispatcher[P, M]) IncrCount(producer P, i int64) {
d.mc += i
d.pmc[producer] += i
if d.expel && d.mc <= 0 {
d.abort <- struct{}{}
close(d.abort)
}
}

Expand Down Expand Up @@ -190,7 +190,6 @@ func (d *Dispatcher[P, M]) Start() *Dispatcher[P, M] {
if ch := d.closedHandler.Load(); ch != nil {
(*ch)(&Action[P, M]{d: d, unlock: true})
}
close(d.abort)
}(d)
return d
}
Expand Down
13 changes: 11 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,20 @@ func (srv *Server) shutdown(err error) {
log.Error("Server", log.String("state", "shutdown"), log.Err(err))
}

var infoCount int
for srv.messageCounter.Load() > 0 {
log.Info("Server", log.Any("network", srv.network), log.String("listen", srv.addr),
log.String("action", "shutdown"), log.String("state", "waiting"), log.Int64("message", srv.messageCounter.Load()))
if infoCount%10 == 0 {
log.Info("Server",
log.Any("network", srv.network),
log.String("listen", srv.addr),
log.String("action", "shutdown"),
log.String("state", "waiting"),
log.Int64("message", srv.messageCounter.Load()))
}
time.Sleep(time.Second)
infoCount++
}
srv.dispatcherMgr.Wait()
if srv.multiple == nil {
srv.OnStopEvent()
}
Expand Down

0 comments on commit af23744

Please sign in to comment.