From 8a86b94aefd33bd720a337a645da8b23047b1381 Mon Sep 17 00:00:00 2001 From: Alexander Yastrebov Date: Wed, 1 Jun 2022 00:30:31 +0000 Subject: [PATCH] net/http: remove unused doneChan The https://golang.org/cl/43230 removed use of `getDoneChan`. Change-Id: I33390c0e3aea6d98367363773ebe39d9c1f64ae9 GitHub-Last-Rev: fe1e4154eaad4e485acfe4272f27d63367144e47 GitHub-Pull-Request: golang/go#53172 Reviewed-on: https://go-review.googlesource.com/c/go/+/409538 Run-TryBot: Damien Neil Reviewed-by: Damien Neil Reviewed-by: hopehook Reviewed-by: Cherry Mui TryBot-Result: Gopher Robot --- src/net/http/server.go | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/src/net/http/server.go b/src/net/http/server.go index 47b6070e1a..9aea1b8002 100644 --- a/src/net/http/server.go +++ b/src/net/http/server.go @@ -2680,37 +2680,11 @@ type Server struct { mu sync.Mutex listeners map[*net.Listener]struct{} activeConn map[*conn]struct{} - doneChan chan struct{} onShutdown []func() listenerGroup sync.WaitGroup } -func (s *Server) getDoneChan() <-chan struct{} { - s.mu.Lock() - defer s.mu.Unlock() - return s.getDoneChanLocked() -} - -func (s *Server) getDoneChanLocked() chan struct{} { - if s.doneChan == nil { - s.doneChan = make(chan struct{}) - } - return s.doneChan -} - -func (s *Server) closeDoneChanLocked() { - ch := s.getDoneChanLocked() - select { - case <-ch: - // Already closed. Don't close again. - default: - // Safe to close here. We're the only closer, guarded - // by s.mu. - close(ch) - } -} - // Close immediately closes all active net.Listeners and any // connections in state StateNew, StateActive, or StateIdle. For a // graceful shutdown, use Shutdown. @@ -2724,7 +2698,6 @@ func (srv *Server) Close() error { srv.inShutdown.Store(true) srv.mu.Lock() defer srv.mu.Unlock() - srv.closeDoneChanLocked() err := srv.closeListenersLocked() // Unlock srv.mu while waiting for listenerGroup. @@ -2776,7 +2749,6 @@ func (srv *Server) Shutdown(ctx context.Context) error { srv.mu.Lock() lnerr := srv.closeListenersLocked() - srv.closeDoneChanLocked() for _, f := range srv.onShutdown { go f() } @@ -3061,10 +3033,8 @@ func (srv *Server) Serve(l net.Listener) error { for { rw, err := l.Accept() if err != nil { - select { - case <-srv.getDoneChan(): + if srv.shuttingDown() { return ErrServerClosed - default: } if ne, ok := err.(net.Error); ok && ne.Temporary() { if tempDelay == 0 {