-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Labels
Description
What happened:
After reloading corefile through plugin/reload, plugin/auto does not call OnShutdown of each zone. So there are multiple zone.reload tasks.
What you expected to happen:
After reloading corefile through plugin/reload, plugin/auto should call OnShutdown for each zone.
How to reproduce it (as minimally and precisely as possible):
- Prepare a simple zonefile, i.e, db.example.com like this:
@ 120 IN SOA examplens.com. example.email.com. 2024052714 900 180 1209600 180
- Prepare a Corefile like this:
example.com:53 {
view myName
auto {
directory zonefile/ db\.(.*) {1}
}
errors
reload
}
- Add codes for the file/reload.go:
Add the following code before line 22 to observe which Zone object is calling the file.Reload().
fmt.Printf("%v: reload called by %p\n", time.Now(), z)
Add the following code before line 53 to observe which Zone object is about to stop the file.Reload().
fmt.Printf("%v: reloadShutdown called by %p\n", time.Now(), z)
Lines 18 to 57 in a7ed346
| go func() { | |
| for { | |
| select { | |
| case <-tick.C: | |
| zFile := z.File() | |
| reader, err := os.Open(filepath.Clean(zFile)) | |
| if err != nil { | |
| log.Errorf("Failed to open zone %q in %q: %v", z.origin, zFile, err) | |
| continue | |
| } | |
| serial := z.SOASerialIfDefined() | |
| zone, err := Parse(reader, z.origin, zFile, serial) | |
| reader.Close() | |
| if err != nil { | |
| if _, ok := err.(*serialErr); !ok { | |
| log.Errorf("Parsing zone %q: %v", z.origin, err) | |
| } | |
| continue | |
| } | |
| // copy elements we need | |
| z.Lock() | |
| z.Apex = zone.Apex | |
| z.Tree = zone.Tree | |
| z.Unlock() | |
| log.Infof("Successfully reloaded zone %q in %q with %d SOA serial", z.origin, zFile, z.Apex.SOA.Serial) | |
| if t != nil { | |
| if err := t.Notify(z.origin); err != nil { | |
| log.Warningf("Failed sending notifies: %s", err) | |
| } | |
| } | |
| case <-z.reloadShutdown: | |
| tick.Stop() | |
| return | |
| } | |
| } | |
| }() |
- Run it and randomly change corefile
For convenience, just randomly change the viewname of the plugin/view.
The result should like
Every time Corefile is reloaded, there will be one more zone.reload task. From 0xc0001f4700, to 0xc0001f40e0 and 0xc0000c6000. The reloadShutdown has never been called.
API server listening at: 127.0.0.1:33987
[INFO] plugin/auto: Inserting zone `example.com.' from: zonefile/db.example.com
example.com.:8853
[INFO] plugin/reload: Running configuration SHA512 = a5f02......
CoreDNS-1.11.2
linux/amd64, go1.21.8,
2024-05-27 15:02:20.099058717 +0800 CST m=+60.038004408: reload called by 0xc0001f4700
2024-05-27 15:03:20.099402522 +0800 CST m=+120.038348212: reload called by 0xc0001f4700
2024-05-27 15:04:20.101689809 +0800 CST m=+180.040635500: reload called by 0xc0001f4700
[INFO] Reloading
[INFO] plugin/auto: Inserting zone `example.com.' from: zonefile/db.example.com
[INFO] plugin/reload: Running configuration SHA512 = 5f6f......
[INFO] Reloading complete
2024-05-27 15:05:20.099387691 +0800 CST m=+240.038333382: reload called by 0xc0001f4700
2024-05-27 15:05:23.290051373 +0800 CST m=+243.228997061: reload called by 0xc0001f40e0
2024-05-27 15:06:20.101795839 +0800 CST m=+300.040741527: reload called by 0xc0001f4700
2024-05-27 15:06:23.294376535 +0800 CST m=+303.233322225: reload called by 0xc0001f40e0
[INFO] Reloading
[INFO] plugin/auto: Inserting zone `example.com.' from: zonefile/db.example.com
[INFO] plugin/reload: Running configuration SHA512 = c327......
[INFO] Reloading complete
2024-05-27 15:07:20.102449586 +0800 CST m=+360.041395277: reload called by 0xc0001f4700
2024-05-27 15:07:23.291320171 +0800 CST m=+363.230265861: reload called by 0xc0001f40e0
2024-05-27 15:07:57.956800234 +0800 CST m=+397.895745924: reload called by 0xc0000c6000
2024-05-27 15:08:20.10066879 +0800 CST m=+420.039614481: reload called by 0xc0001f4700
2024-05-27 15:08:23.290353692 +0800 CST m=+423.229299384: reload called by 0xc0001f40e0
2024-05-27 15:08:57.957756658 +0800 CST m=+457.896702348: reload called by 0xc0000c6000
Environment:
coredns v1.11.2
ubuntu 22.04 lts