mirror of
https://github.com/coredns/coredns.git
synced 2026-10-08 19:45:21 -04:00
plugin/file: Fix race condition in file plugin closer (#8583)
This PR fixes race condition in file plugin closer Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
@@ -8,9 +8,14 @@ import (
|
||||
|
||||
// ClosestEncloser returns the closest encloser for qname.
|
||||
func (z *Zone) ClosestEncloser(qname string) (*tree.Elem, bool) {
|
||||
_, zoneTree := z.snapshot()
|
||||
if zoneTree == nil {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
offset, end := dns.NextLabel(qname, 0)
|
||||
for !end {
|
||||
elem, _ := z.Search(qname)
|
||||
elem, _ := zoneTree.Search(qname)
|
||||
if elem != nil {
|
||||
return elem, true
|
||||
}
|
||||
@@ -19,5 +24,5 @@ func (z *Zone) ClosestEncloser(qname string) (*tree.Elem, bool) {
|
||||
offset, end = dns.NextLabel(qname, 0)
|
||||
}
|
||||
|
||||
return z.Search(z.origin)
|
||||
return zoneTree.Search(z.origin)
|
||||
}
|
||||
|
||||
@@ -37,3 +37,27 @@ func TestClosestEncloser(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestClosestEncloserConcurrentSetData(t *testing.T) {
|
||||
z, err := Parse(strings.NewReader(dbMiekNL), testzone, "stdin", 0)
|
||||
if err != nil {
|
||||
t.Fatalf("Expect no error when reading zone, got %q", err)
|
||||
}
|
||||
|
||||
apex, zoneTree := z.snapshot()
|
||||
start := make(chan struct{})
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer close(done)
|
||||
<-start
|
||||
for range 10000 {
|
||||
z.setData(apex, zoneTree)
|
||||
}
|
||||
}()
|
||||
|
||||
close(start)
|
||||
for range 10000 {
|
||||
z.ClosestEncloser("blaat.www.miek.nl.")
|
||||
}
|
||||
<-done
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user