mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
Close idle connections after graceful shutdown timeout
This commit is contained in:
parent
b23eec4fac
commit
37ae21001d
1 changed files with 11 additions and 0 deletions
|
@ -52,6 +52,16 @@ func NewServer(addr string, group []*SiteConfig) (*Server, error) {
|
|||
connTimeout: GracefulTimeout,
|
||||
}
|
||||
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
|
||||
if !HTTP2 {
|
||||
|
@ -288,6 +298,7 @@ func (s *Server) Stop() (err error) {
|
|||
s.listenerMu.Lock()
|
||||
if s.listener != nil {
|
||||
err = s.listener.Close()
|
||||
s.listener = nil
|
||||
}
|
||||
s.listenerMu.Unlock()
|
||||
|
||||
|
|
Loading…
Reference in a new issue