mirror of
https://github.com/coredns/coredns.git
synced 2025-11-27 14:14:02 -05:00
Fixes races in test and klog (#3079)
Various fixes to make things less flaky: * kubernetes: put klog.SetOutput in the setup function, not in the init function to see if that helps * file: make z.Expired a boolean instead of a pointer to a boolean * test: fix TestSecondaryZoneTransfer test, which wasn't actually testing in the right way. It's more right now, but may still be racy (race introduced because a file's lazy loading of zones) Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
@@ -72,7 +72,7 @@ func (f File) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (i
|
||||
z.RLock()
|
||||
exp := z.Expired
|
||||
z.RUnlock()
|
||||
if exp != nil && *exp {
|
||||
if exp {
|
||||
log.Errorf("Zone %s is expired", zone)
|
||||
return dns.RcodeServerFailure, nil
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ Transfer:
|
||||
z.Lock()
|
||||
z.Tree = z1.Tree
|
||||
z.Apex = z1.Apex
|
||||
*z.Expired = false
|
||||
z.Expired = false
|
||||
z.Unlock()
|
||||
log.Infof("Transferred: %s from %s", z.origin, tr)
|
||||
return nil
|
||||
@@ -129,7 +129,7 @@ Restart:
|
||||
if !retryActive {
|
||||
break
|
||||
}
|
||||
*z.Expired = true
|
||||
z.Expired = true
|
||||
|
||||
case <-retryTicker.C:
|
||||
if !retryActive {
|
||||
|
||||
@@ -125,7 +125,6 @@ func TestTransferIn(t *testing.T) {
|
||||
defer s.Shutdown()
|
||||
|
||||
z := new(Zone)
|
||||
z.Expired = new(bool)
|
||||
z.origin = testZone
|
||||
z.TransferFrom = []string{addrstr}
|
||||
|
||||
@@ -140,7 +139,6 @@ func TestTransferIn(t *testing.T) {
|
||||
|
||||
func TestIsNotify(t *testing.T) {
|
||||
z := new(Zone)
|
||||
z.Expired = new(bool)
|
||||
z.origin = testZone
|
||||
state := newRequest(testZone, dns.TypeSOA)
|
||||
// need to set opcode
|
||||
|
||||
@@ -22,7 +22,7 @@ type Zone struct {
|
||||
file string
|
||||
*tree.Tree
|
||||
Apex
|
||||
Expired *bool
|
||||
Expired bool
|
||||
|
||||
sync.RWMutex
|
||||
|
||||
@@ -46,16 +46,13 @@ type Apex struct {
|
||||
|
||||
// NewZone returns a new zone.
|
||||
func NewZone(name, file string) *Zone {
|
||||
z := &Zone{
|
||||
return &Zone{
|
||||
origin: dns.Fqdn(name),
|
||||
origLen: dns.CountLabel(dns.Fqdn(name)),
|
||||
file: filepath.Clean(file),
|
||||
Tree: &tree.Tree{},
|
||||
Expired: new(bool),
|
||||
reloadShutdown: make(chan bool),
|
||||
}
|
||||
*z.Expired = false
|
||||
return z
|
||||
}
|
||||
|
||||
// Copy copies a zone.
|
||||
|
||||
Reference in New Issue
Block a user