mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 02:33:14 -04:00
Make middleware survive a restart (#142)
Make middleware that sets up a (http) handler survive a graceful restart. We calls the middleware's Shutdown function(s). If restart fails the Start function is called again. * middleware/health: OK * middleware/pprof: OK * middleware/metrics: OK All restart OK.
This commit is contained in:
@@ -445,32 +445,6 @@ func (s *Server) RunFirstStartupFuncs() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// tcpKeepAliveListener sets TCP keep-alive timeouts on accepted
|
||||
// connections. It's used by ListenAndServe and ListenAndServeTLS so
|
||||
// dead TCP connections (e.g. closing laptop mid-download) eventually
|
||||
// go away.
|
||||
//
|
||||
// Borrowed from the Go standard library.
|
||||
type tcpKeepAliveListener struct {
|
||||
*net.TCPListener
|
||||
}
|
||||
|
||||
// Accept accepts the connection with a keep-alive enabled.
|
||||
func (ln tcpKeepAliveListener) Accept() (c net.Conn, err error) {
|
||||
tc, err := ln.AcceptTCP()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
tc.SetKeepAlive(true)
|
||||
tc.SetKeepAlivePeriod(3 * time.Minute)
|
||||
return tc, nil
|
||||
}
|
||||
|
||||
// File implements ListenerFile; returns the underlying file of the listener.
|
||||
func (ln tcpKeepAliveListener) File() (*os.File, error) {
|
||||
return ln.TCPListener.File()
|
||||
}
|
||||
|
||||
// ShutdownCallbacks executes all the shutdown callbacks
|
||||
// for all the virtualhosts in servers, and returns all the
|
||||
// errors generated during their execution. In other words,
|
||||
@@ -493,6 +467,21 @@ func ShutdownCallbacks(servers []*Server) []error {
|
||||
return errs
|
||||
}
|
||||
|
||||
func StartupCallbacks(servers []*Server) []error {
|
||||
var errs []error
|
||||
for _, s := range servers {
|
||||
for _, zone := range s.zones {
|
||||
for _, startupFunc := range zone.config.Startup {
|
||||
err := startupFunc()
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return errs
|
||||
}
|
||||
|
||||
func RcodeNoClientWrite(rcode int) bool {
|
||||
switch rcode {
|
||||
case dns.RcodeServerFailure:
|
||||
|
||||
Reference in New Issue
Block a user