plugin/file: shutdown reload goroutine (#1571)
* plugin/file: shutdown reload goroutine Shutdown the z.Reload() routine (if started in the first place) on shutdow and reload. Fixes #1508 * Must be put in c.OnShutdown() * up test coverage
This commit is contained in:
parent
6bb08ffee4
commit
4f3dc207a4
6 changed files with 32 additions and 5 deletions
|
@ -60,8 +60,8 @@ func (z *Zones) Add(zo *file.Zone, name string) {
|
||||||
func (z *Zones) Remove(name string) {
|
func (z *Zones) Remove(name string) {
|
||||||
z.Lock()
|
z.Lock()
|
||||||
|
|
||||||
if zo, ok := z.Z[name]; ok && !zo.NoReload {
|
if zo, ok := z.Z[name]; ok {
|
||||||
zo.ReloadShutdown <- true
|
zo.OnShutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(z.Z, name)
|
delete(z.Z, name)
|
||||||
|
|
|
@ -47,7 +47,7 @@ func (z *Zone) Reload() error {
|
||||||
log.Printf("[INFO] Successfully reloaded zone %q in %q with serial %d", z.origin, z.file, z.Apex.SOA.Serial)
|
log.Printf("[INFO] Successfully reloaded zone %q in %q with serial %d", z.origin, z.file, z.Apex.SOA.Serial)
|
||||||
z.Notify()
|
z.Notify()
|
||||||
|
|
||||||
case <-z.ReloadShutdown:
|
case <-z.reloadShutdown:
|
||||||
tick.Stop()
|
tick.Stop()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,10 @@ func setup(c *caddy.Controller) error {
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
for _, n := range zones.Names {
|
||||||
|
z := zones.Z[n]
|
||||||
|
c.OnShutdown(z.OnShutdown)
|
||||||
|
}
|
||||||
|
|
||||||
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
||||||
return File{Next: next, Zones: zones}
|
return File{Next: next, Zones: zones}
|
||||||
|
|
|
@ -53,6 +53,20 @@ func TestFileParse(t *testing.T) {
|
||||||
false,
|
false,
|
||||||
Zones{Names: []string{"10.in-addr.arpa."}},
|
Zones{Names: []string{"10.in-addr.arpa."}},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
`file ` + zoneFileName1 + ` example.net. {
|
||||||
|
upstream a
|
||||||
|
}`,
|
||||||
|
true,
|
||||||
|
Zones{Names: []string{}},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`file ` + zoneFileName1 + ` example.net. {
|
||||||
|
no_rebloat
|
||||||
|
}`,
|
||||||
|
true,
|
||||||
|
Zones{Names: []string{}},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
|
|
9
plugin/file/shutdown.go
Normal file
9
plugin/file/shutdown.go
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
package file
|
||||||
|
|
||||||
|
// OnShutdown shuts down any running go-routines for this zone.
|
||||||
|
func (z *Zone) OnShutdown() error {
|
||||||
|
if !z.NoReload {
|
||||||
|
z.reloadShutdown <- true
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -29,7 +29,7 @@ type Zone struct {
|
||||||
|
|
||||||
NoReload bool
|
NoReload bool
|
||||||
reloadMu sync.RWMutex
|
reloadMu sync.RWMutex
|
||||||
ReloadShutdown chan bool
|
reloadShutdown chan bool
|
||||||
Upstream upstream.Upstream // Upstream for looking up names during the resolution process
|
Upstream upstream.Upstream // Upstream for looking up names during the resolution process
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ func NewZone(name, file string) *Zone {
|
||||||
file: path.Clean(file),
|
file: path.Clean(file),
|
||||||
Tree: &tree.Tree{},
|
Tree: &tree.Tree{},
|
||||||
Expired: new(bool),
|
Expired: new(bool),
|
||||||
ReloadShutdown: make(chan bool),
|
reloadShutdown: make(chan bool),
|
||||||
}
|
}
|
||||||
*z.Expired = false
|
*z.Expired = false
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue