Fix graceful reload (#141)

Fix CoreDNS graceful reloading. This uses the same stuff as Caddy
(obviously), but extends it for UDP listeners as well. Also add to the
README that we *will* call Shutdown for middleware.

Fixes #4
This commit is contained in:
Miek Gieben
2016-04-28 21:15:45 +01:00
parent e34280e7af
commit a1478f891d
5 changed files with 91 additions and 130 deletions

View File

@@ -81,9 +81,14 @@ func Restart(newCorefile Input) error {
// Add file descriptors of all the sockets
serversMu.Lock()
for i, s := range servers {
j := 0
for _, s := range servers {
extraFiles = append(extraFiles, s.ListenerFd())
crfileGob.ListenerFds[s.Addr] = uintptr(4 + i) // 4 fds come before any of the listeners
extraFiles = append(extraFiles, s.PacketConnFd())
// So this will be 0 1 2 3 TCP UDP TCP UDP ... etc.
crfileGob.ListenerFds["tcp"+s.Addr] = uintptr(4 + j) // 4 fds come before any of the listeners
crfileGob.ListenerFds["udp"+s.Addr] = uintptr(4 + j + 1) // add udp after that
j += 2
}
serversMu.Unlock()