From 51a11b3664dba1a5e524e1b3f81a5e227d8b828e Mon Sep 17 00:00:00 2001 From: Yong Tang Date: Thu, 5 Mar 2026 18:35:41 -0800 Subject: [PATCH] plugin/reload: Allow disabling jitter with 0s (#7896) This PR fixes #7894 by allowing reload 2s 0s as documented. Signed-off-by: Yong Tang --- plugin/reload/setup.go | 13 ++++++++----- plugin/reload/setup_test.go | 5 +++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/plugin/reload/setup.go b/plugin/reload/setup.go index 65cd68149..47a12e5e4 100644 --- a/plugin/reload/setup.go +++ b/plugin/reload/setup.go @@ -52,16 +52,19 @@ func setup(c *caddy.Controller) error { } j = d } - if j < minJitter { - return plugin.Error("reload", fmt.Errorf("jitter value must be greater or equal to %v", minJitter)) + + if j != 0 && j < minJitter { + return plugin.Error("reload", fmt.Errorf("jitter value must be 0 or greater or equal to %v", minJitter)) } - if j > i/2 { + if j > 0 && j > i/2 { j = i / 2 } - jitter := time.Duration(rand.Int63n(j.Nanoseconds()) - (j.Nanoseconds() / 2)) // #nosec G404 -- non-cryptographic jitter. - i = i + jitter + if j > 0 { + jitter := time.Duration(rand.Int63n(j.Nanoseconds()) - (j.Nanoseconds() / 2)) // #nosec G404 -- non-cryptographic jitter. + i = i + jitter + } // prepare info for next onInstanceStartup event r.setInterval(i) diff --git a/plugin/reload/setup_test.go b/plugin/reload/setup_test.go index 5450fae57..d7c9ccc15 100644 --- a/plugin/reload/setup_test.go +++ b/plugin/reload/setup_test.go @@ -22,6 +22,11 @@ func TestSetupReload(t *testing.T) { t.Fatalf("Expected no errors, but got: %v", err) } + c = caddy.NewTestController("dns", `reload 2s 0s`) + if err := setup(c); err != nil { + t.Fatalf("Expected no errors, but got: %v", err) + } + c = caddy.NewTestController("dns", `reload foo`) if err := setup(c); err == nil { t.Fatalf("Expected errors, but got: %v", err)