mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 02:03:20 -04:00 
			
		
		
		
	fix(file): fix data race in tree Elem.Name (#7574)
Eagerly set name in newElem and make Name() read-only to avoid racy lazy writes under concurrent lookups. Add tests for empty-name comparisons and concurrent access to Less/Name(). In addition, regression tests to CloudDNS plugin. Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
This commit is contained in:
		| @@ -12,6 +12,8 @@ type Elem struct { | ||||
| func newElem(rr dns.RR) *Elem { | ||||
| 	e := Elem{m: make(map[uint16][]dns.RR)} | ||||
| 	e.m[rr.Header().Rrtype] = []dns.RR{rr} | ||||
| 	// Eagerly set the cached owner name to avoid racy lazy writes later. | ||||
| 	e.name = rr.Header().Name | ||||
| 	return &e | ||||
| } | ||||
|  | ||||
| @@ -56,12 +58,12 @@ func (e *Elem) All() []dns.RR { | ||||
|  | ||||
| // Name returns the name for this node. | ||||
| func (e *Elem) Name() string { | ||||
| 	// Read-only: name is eagerly set in newElem and should not be mutated here. | ||||
| 	if e.name != "" { | ||||
| 		return e.name | ||||
| 	} | ||||
| 	for _, rrs := range e.m { | ||||
| 		e.name = rrs[0].Header().Name | ||||
| 		return e.name | ||||
| 		return rrs[0].Header().Name | ||||
| 	} | ||||
| 	return "" | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user