Files
coredns/plugin/file/closest.go
Yong Tang 594d6c9121 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>
2026-09-29 01:19:07 -07:00

29 lines
536 B
Go

package file
import (
"github.com/coredns/coredns/plugin/file/tree"
"github.com/miekg/dns"
)
// 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, _ := zoneTree.Search(qname)
if elem != nil {
return elem, true
}
qname = qname[offset:]
offset, end = dns.NextLabel(qname, 0)
}
return zoneTree.Search(z.origin)
}