plugin/reload: Allow disabling jitter with 0s (#7896)

This PR fixes #7894 by allowing reload 2s 0s as documented.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang
2026-03-05 18:35:41 -08:00
committed by GitHub
parent 5d97c15488
commit 51a11b3664
2 changed files with 13 additions and 5 deletions

View File

@@ -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)