Commit 34aad168 authored by Dan Peterson's avatar Dan Peterson Committed by Brad Fitzpatrick

net/http: fix receiver for Server.Shutdown and Server.Close

Change-Id: Ia27ca728bafcf20d001b477787b21d16ae12960d
Reviewed-on: https://go-review.googlesource.com/33552Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 06fcc32d
...@@ -2405,14 +2405,14 @@ func (s *Server) closeDoneChanLocked() { ...@@ -2405,14 +2405,14 @@ func (s *Server) closeDoneChanLocked() {
// //
// Close returns any error returned from closing the Server's // Close returns any error returned from closing the Server's
// underlying Listener(s). // underlying Listener(s).
func (s *Server) Close() error { func (srv *Server) Close() error {
s.mu.Lock() srv.mu.Lock()
defer s.mu.Unlock() defer srv.mu.Unlock()
s.closeDoneChanLocked() srv.closeDoneChanLocked()
err := s.closeListenersLocked() err := srv.closeListenersLocked()
for c := range s.activeConn { for c := range srv.activeConn {
c.rwc.Close() c.rwc.Close()
delete(s.activeConn, c) delete(srv.activeConn, c)
} }
return err return err
} }
...@@ -2437,19 +2437,19 @@ var shutdownPollInterval = 500 * time.Millisecond ...@@ -2437,19 +2437,19 @@ var shutdownPollInterval = 500 * time.Millisecond
// connections such as WebSockets. The caller of Shutdown should // connections such as WebSockets. The caller of Shutdown should
// separately notify such long-lived connections of shutdown and wait // separately notify such long-lived connections of shutdown and wait
// for them to close, if desired. // for them to close, if desired.
func (s *Server) Shutdown(ctx context.Context) error { func (srv *Server) Shutdown(ctx context.Context) error {
atomic.AddInt32(&s.inShutdown, 1) atomic.AddInt32(&srv.inShutdown, 1)
defer atomic.AddInt32(&s.inShutdown, -1) defer atomic.AddInt32(&srv.inShutdown, -1)
s.mu.Lock() srv.mu.Lock()
lnerr := s.closeListenersLocked() lnerr := srv.closeListenersLocked()
s.closeDoneChanLocked() srv.closeDoneChanLocked()
s.mu.Unlock() srv.mu.Unlock()
ticker := time.NewTicker(shutdownPollInterval) ticker := time.NewTicker(shutdownPollInterval)
defer ticker.Stop() defer ticker.Stop()
for { for {
if s.closeIdleConns() { if srv.closeIdleConns() {
return lnerr return lnerr
} }
select { select {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment