mirror of
https://github.com/coredns/coredns.git
synced 2026-04-13 23:45:33 -04:00
Fix data race in xfr.go (#8039)
Signed-off-by: Ryan Brewster <rpb@anthropic.com>
This commit is contained in:
@@ -19,8 +19,12 @@ func (f File) Transfer(zone string, serial uint32) (<-chan []dns.RR, error) {
|
||||
// Transfer transfers a zone with serial in the returned channel and implements IXFR fallback, by just
|
||||
// sending a single SOA record.
|
||||
func (z *Zone) Transfer(serial uint32) (<-chan []dns.RR, error) {
|
||||
// get soa and apex
|
||||
apex, err := z.ApexIfDefined()
|
||||
// Snapshot apex and tree under one read lock so the goroutine walks the
|
||||
// same generation the SOA came from, even if TransferIn swaps them mid-AXFR.
|
||||
z.RLock()
|
||||
apex, err := z.apexIfDefinedLocked()
|
||||
t := z.Tree
|
||||
z.RUnlock()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -35,7 +39,7 @@ func (z *Zone) Transfer(serial uint32) (<-chan []dns.RR, error) {
|
||||
}
|
||||
|
||||
ch <- apex
|
||||
z.Walk(func(e *tree.Elem, _ map[uint16][]dns.RR) error { ch <- e.All(); return nil })
|
||||
t.Walk(func(e *tree.Elem, _ map[uint16][]dns.RR) error { ch <- e.All(); return nil })
|
||||
ch <- []dns.RR{apex[0]}
|
||||
|
||||
close(ch)
|
||||
|
||||
@@ -146,6 +146,11 @@ func (z *Zone) SetFile(path string) {
|
||||
func (z *Zone) ApexIfDefined() ([]dns.RR, error) {
|
||||
z.RLock()
|
||||
defer z.RUnlock()
|
||||
return z.apexIfDefinedLocked()
|
||||
}
|
||||
|
||||
// apexIfDefinedLocked is ApexIfDefined without locking; caller must hold z's read lock.
|
||||
func (z *Zone) apexIfDefinedLocked() ([]dns.RR, error) {
|
||||
if z.SOA == nil {
|
||||
return nil, fmt.Errorf("no SOA")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user