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:
Yong Tang
2026-07-13 17:33:51 -07:00
committed by GitHub
parent 38e26f25c4
commit e5053d50ad
2 changed files with 24 additions and 3 deletions

View File

@@ -152,9 +152,9 @@ Restart:
return nil return nil
} }
soa := z.getSOA() soa := z.getSOA()
refresh := time.Second * time.Duration(soa.Refresh) refresh := time.Second * time.Duration(max(soa.Refresh, 1))
retry := time.Second * time.Duration(soa.Retry) retry := time.Second * time.Duration(max(soa.Retry, 1))
expire := time.Second * time.Duration(soa.Expire) expire := time.Second * time.Duration(max(soa.Expire, 1))
refreshTicker := time.NewTicker(refresh) refreshTicker := time.NewTicker(refresh)
retryTicker := time.NewTicker(retry) retryTicker := time.NewTicker(retry)

View File

@@ -7,6 +7,7 @@ import (
"github.com/coredns/coredns/plugin/pkg/dnstest" "github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/test" "github.com/coredns/coredns/plugin/test"
"github.com/coredns/coredns/plugin/transfer"
"github.com/coredns/coredns/request" "github.com/coredns/coredns/request"
"github.com/miekg/dns" "github.com/miekg/dns"
@@ -166,3 +167,23 @@ func newRequest(_zone string, _qtype uint16) request.Request {
m.SetEdns0(4097, true) m.SetEdns0(4097, true)
return request.Request{W: &test.ResponseWriter{}, Req: m} 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)
}
}