@@ -2680,37 +2680,11 @@ type Server struct {
2680
2680
mu sync.Mutex
2681
2681
listeners map [* net.Listener ]struct {}
2682
2682
activeConn map [* conn ]struct {}
2683
- doneChan chan struct {}
2684
2683
onShutdown []func ()
2685
2684
2686
2685
listenerGroup sync.WaitGroup
2687
2686
}
2688
2687
2689
- func (s * Server ) getDoneChan () <- chan struct {} {
2690
- s .mu .Lock ()
2691
- defer s .mu .Unlock ()
2692
- return s .getDoneChanLocked ()
2693
- }
2694
-
2695
- func (s * Server ) getDoneChanLocked () chan struct {} {
2696
- if s .doneChan == nil {
2697
- s .doneChan = make (chan struct {})
2698
- }
2699
- return s .doneChan
2700
- }
2701
-
2702
- func (s * Server ) closeDoneChanLocked () {
2703
- ch := s .getDoneChanLocked ()
2704
- select {
2705
- case <- ch :
2706
- // Already closed. Don't close again.
2707
- default :
2708
- // Safe to close here. We're the only closer, guarded
2709
- // by s.mu.
2710
- close (ch )
2711
- }
2712
- }
2713
-
2714
2688
// Close immediately closes all active net.Listeners and any
2715
2689
// connections in state StateNew, StateActive, or StateIdle. For a
2716
2690
// graceful shutdown, use Shutdown.
@@ -2724,7 +2698,6 @@ func (srv *Server) Close() error {
2724
2698
srv .inShutdown .Store (true )
2725
2699
srv .mu .Lock ()
2726
2700
defer srv .mu .Unlock ()
2727
- srv .closeDoneChanLocked ()
2728
2701
err := srv .closeListenersLocked ()
2729
2702
2730
2703
// Unlock srv.mu while waiting for listenerGroup.
@@ -2776,7 +2749,6 @@ func (srv *Server) Shutdown(ctx context.Context) error {
2776
2749
2777
2750
srv .mu .Lock ()
2778
2751
lnerr := srv .closeListenersLocked ()
2779
- srv .closeDoneChanLocked ()
2780
2752
for _ , f := range srv .onShutdown {
2781
2753
go f ()
2782
2754
}
@@ -3061,10 +3033,8 @@ func (srv *Server) Serve(l net.Listener) error {
3061
3033
for {
3062
3034
rw , err := l .Accept ()
3063
3035
if err != nil {
3064
- select {
3065
- case <- srv .getDoneChan ():
3036
+ if srv .shuttingDown () {
3066
3037
return ErrServerClosed
3067
- default :
3068
3038
}
3069
3039
if ne , ok := err .(net.Error ); ok && ne .Temporary () {
3070
3040
if tempDelay == 0 {
0 commit comments