Commit 01e05afa authored by Matt Holt's avatar Matt Holt

Merge pull request #870 from mholt/close-idle-conn

Close idle connections after graceful shutdown timeout
parents e7fc26e3 37ae2100
...@@ -52,6 +52,16 @@ func NewServer(addr string, group []*SiteConfig) (*Server, error) { ...@@ -52,6 +52,16 @@ func NewServer(addr string, group []*SiteConfig) (*Server, error) {
connTimeout: GracefulTimeout, connTimeout: GracefulTimeout,
} }
s.Server.Handler = s // this is weird, but whatever s.Server.Handler = s // this is weird, but whatever
s.Server.ConnState = func(c net.Conn, cs http.ConnState) {
if cs == http.StateIdle {
s.listenerMu.Lock()
// server stopped, close idle connection
if s.listener == nil {
c.Close()
}
s.listenerMu.Unlock()
}
}
// Disable HTTP/2 if desired // Disable HTTP/2 if desired
if !HTTP2 { if !HTTP2 {
...@@ -288,6 +298,7 @@ func (s *Server) Stop() (err error) { ...@@ -288,6 +298,7 @@ func (s *Server) Stop() (err error) {
s.listenerMu.Lock() s.listenerMu.Lock()
if s.listener != nil { if s.listener != nil {
err = s.listener.Close() err = s.listener.Close()
s.listener = nil
} }
s.listenerMu.Unlock() s.listenerMu.Unlock()
......
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