feat: count graceful HTTP2 goaways

This commit is contained in:
2026-09-22 23:16:06 +08:00
parent de33eda846
commit 7e9e8aa67c
4 changed files with 9 additions and 4 deletions

View File

@@ -57,6 +57,7 @@ type Server struct {
rejectedConns atomic.Uint64
rejectedReqs atomic.Uint64
protocolErrors atomic.Uint64
goAwaySent atomic.Uint64
activeConns atomic.Int64
activeRequests atomic.Int64
wg sync.WaitGroup
@@ -69,6 +70,7 @@ type Stats struct {
RejectedConnections uint64 `json:"rejectedConnections"`
RejectedRequests uint64 `json:"rejectedRequests"`
ProtocolErrors uint64 `json:"protocolErrors"`
GoAwaySent uint64 `json:"goAwaySent"`
ActiveConnections int64 `json:"activeConnections"`
ActiveRequests int64 `json:"activeRequests"`
}
@@ -93,6 +95,7 @@ func (s *Server) Stats() Stats {
RejectedConnections: s.rejectedConns.Load(),
RejectedRequests: s.rejectedReqs.Load(),
ProtocolErrors: s.protocolErrors.Load(),
GoAwaySent: s.goAwaySent.Load(),
ActiveConnections: s.activeConns.Load(),
ActiveRequests: s.activeRequests.Load(),
}
@@ -374,6 +377,7 @@ func (s *Server) Shutdown(ctx context.Context) error {
s.mu.Unlock()
return nil
}
alreadyClosing := s.closing
s.closing = true
listener := s.listener
shutdownConfig := s.shutdownConfig
@@ -389,7 +393,8 @@ func (s *Server) Shutdown(ctx context.Context) error {
// x/net/http2's configured shutdown callback sends GOAWAY and lets active
// streams finish. The base request context remains live until the timeout
// path below, where connections are forcibly closed.
if shutdownConfig != nil {
if shutdownConfig != nil && !alreadyClosing {
s.goAwaySent.Add(uint64(len(connections)))
_ = shutdownConfig.Shutdown(context.Background())
}