From 9a90400821c9df5131b8e3ab84a2575ec8c25bba Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 12 Jul 2018 10:21:49 -0700 Subject: [PATCH] agent/checks: prevent overflow of backoff --- agent/checks/alias.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/agent/checks/alias.go b/agent/checks/alias.go index 5a40693c54..e6c7082e57 100644 --- a/agent/checks/alias.go +++ b/agent/checks/alias.go @@ -120,7 +120,11 @@ func (c *CheckAlias) runQuery(stopCh chan struct{}) { // Backoff if we have to if attempt > checkAliasBackoffMin { - waitTime := (1 << (attempt - checkAliasBackoffMin)) * time.Second + shift := attempt - checkAliasBackoffMin + if shift > 31 { + shift = 31 // so we don't overflow to 0 + } + waitTime := (1 << shift) * time.Second if waitTime > checkAliasBackoffMaxWait { waitTime = checkAliasBackoffMaxWait }