From a8b6395faa6a5234cd1741df01c38830aba702dc Mon Sep 17 00:00:00 2001 From: Stephan Renatus Date: Mon, 12 Sep 2022 18:01:15 +0200 Subject: [PATCH] util/backoff: seed math/rand source (#5124) It has a negligible impact, but since security scanners like gosec will pick this up, let's do it in a way that'll pass inspection. Signed-off-by: Stephan Renatus --- util/backoff.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/util/backoff.go b/util/backoff.go index 1b126fbee4..944b572805 100644 --- a/util/backoff.go +++ b/util/backoff.go @@ -9,6 +9,15 @@ import ( "time" ) +func init() { + // NOTE(sr): We don't need good random numbers here; it's used for jittering + // the backup timing a bit. But anyways, let's make it random enough; without + // a call to rand.Seed() we'd get the same stream of numbers for each program + // run. (Or not, if some other packages happens to seed the global randomness + // source.) + rand.Seed(time.Now().UnixNano()) +} + // DefaultBackoff returns a delay with an exponential backoff based on the // number of retries. func DefaultBackoff(base, max float64, retries int) time.Duration {