From 98de6aebf7b139cd7ab3a93972ef9b9c1e378c1d Mon Sep 17 00:00:00 2001 From: WeidiDeng Date: Tue, 22 Oct 2024 13:35:35 +0800 Subject: [PATCH] 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 --- http3/server.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/http3/server.go b/http3/server.go index ac0f71774d8..097a8005dfb 100644 --- a/http3/server.go +++ b/http3/server.go @@ -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