http3: fix graceful server shutdown (#4707)

* close connHandlingDone once only when the server is shutting down

* close underlying listeners during graceful  shutdown when there is no connection

* remove connDoneOnce
This commit is contained in:
WeidiDeng
2024-10-22 13:35:35 +08:00
committed by GitHub
parent 6af2b1a478
commit 98de6aebf7

View File

@@ -285,7 +285,7 @@ func (s *Server) init() {
}
func (s *Server) decreaseConnCount() {
if s.connCount.Add(-1) == 0 {
if s.connCount.Add(-1) == 0 && s.graceCtx.Err() != nil {
close(s.connHandlingDone)
}
}
@@ -762,7 +762,7 @@ func (s *Server) Shutdown(ctx context.Context) error {
s.mutex.Unlock()
if s.connCount.Load() == 0 {
return nil
return s.Close()
}
select {
case <-s.connHandlingDone: // all connections were closed