mirror of
https://github.com/coredns/coredns.git
synced 2026-07-16 12:40:11 -04:00
plugin/file: Fix panic on zero-valued SOA refresh (#8276)
This PR fixes panic with zero-valued SOA refresh Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
@@ -152,9 +152,9 @@ Restart:
|
||||
return nil
|
||||
}
|
||||
soa := z.getSOA()
|
||||
refresh := time.Second * time.Duration(soa.Refresh)
|
||||
retry := time.Second * time.Duration(soa.Retry)
|
||||
expire := time.Second * time.Duration(soa.Expire)
|
||||
refresh := time.Second * time.Duration(max(soa.Refresh, 1))
|
||||
retry := time.Second * time.Duration(max(soa.Retry, 1))
|
||||
expire := time.Second * time.Duration(max(soa.Expire, 1))
|
||||
|
||||
refreshTicker := time.NewTicker(refresh)
|
||||
retryTicker := time.NewTicker(retry)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/coredns/coredns/plugin/pkg/dnstest"
|
||||
"github.com/coredns/coredns/plugin/test"
|
||||
"github.com/coredns/coredns/plugin/transfer"
|
||||
"github.com/coredns/coredns/request"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
@@ -166,3 +167,23 @@ func newRequest(_zone string, _qtype uint16) request.Request {
|
||||
m.SetEdns0(4097, true)
|
||||
return request.Request{W: &test.ResponseWriter{}, Req: m}
|
||||
}
|
||||
|
||||
func TestUpdateWithZeroSOATimers(t *testing.T) {
|
||||
z := NewZone(testZone, "test")
|
||||
z.SOA = test.SOA(
|
||||
fmt.Sprintf("%s IN SOA bla. bla. 1 0 0 0 0", testZone),
|
||||
)
|
||||
|
||||
updateShutdown := make(chan bool)
|
||||
time.AfterFunc(10*time.Millisecond, func() {
|
||||
close(updateShutdown)
|
||||
})
|
||||
|
||||
if err := z.UpdateWithTransfer(
|
||||
updateShutdown,
|
||||
nil,
|
||||
func(*Zone, *transfer.Transfer) error { return nil },
|
||||
); err != nil {
|
||||
t.Fatalf("Unexpected update error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user