Skip to content

Commit

Permalink
🐛 Fix serve panics if splay is zero. (#1217)
Browse files Browse the repository at this point in the history
Signed-off-by: Preslav <[email protected]>
  • Loading branch information
preslavgerchev authored Apr 2, 2024
1 parent eba0d80 commit 7d0f974
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion apps/cnspec/cmd/backgroundjob/serve_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ func Serve(timer time.Duration, splay time.Duration, handler JobRunner) {
if err != nil {
log.Error().Err(err).Send()
}
nextRun := timer + time.Duration(rand.Int63n(int64(splay)))
splayDur := time.Duration(0)
if splay > 0 {
splayDur = time.Duration(rand.Int63n(int64(splay)))
}
nextRun := timer + splayDur
log.Info().Msgf("next scan in %v", nextRun)
t.Reset(nextRun)
case <-shutdownChannel:
Expand Down
6 changes: 5 additions & 1 deletion apps/cnspec/cmd/backgroundjob/serve_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ loop:
default:
log.Error().Msg("scan not started. may be stuck")
}
nextRun := m.Timer + time.Duration(rand.Int63n(int64(m.Splay)))
splayDur := time.Duration(0)
if m.Splay > 0 {
splayDur = time.Duration(rand.Int63n(int64(m.Splay)))
}
nextRun := m.Timer + splayDur
log.Info().Msgf("next scan in %v", nextRun)
t.Reset(nextRun)
case c := <-r:
Expand Down

0 comments on commit 7d0f974

Please sign in to comment.