Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
Add seed init when using random number generating.
Browse files Browse the repository at this point in the history
  • Loading branch information
lesovsky committed May 5, 2021
1 parent 89f6ec2 commit 449f4c6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/packaging/autoupdate/autoupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func StartAutoupdateLoop(ctx context.Context, c *Config) {
return
}

rand.Seed(time.Now().UnixNano())
itv := time.Duration(60+rand.Intn(60)) * time.Minute // #nosec G404

log.Info("start background auto-update loop")
Expand Down Expand Up @@ -407,7 +408,7 @@ func updateBinary(sourceFile string, destFile string) error {
return nil
}

// restartSystemdService restart pgscv service.
// restartSystemdService checks privileges and restarts pgscv service.
func restartSystemdService() error {
cmd := exec.Command("systemctl", "restart", "pgscv.service")
// after cmd.Start execution of this code could be interrupted, end even err might not be handled.
Expand Down
2 changes: 2 additions & 0 deletions internal/pgscv/pgscv.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ func (s *sendClient) sendMetrics(buf []byte) error {

// addDelay increments passed delay to random value between 1 and 10 seconds.
func addDelay(d time.Duration) time.Duration {
rand.Seed(time.Now().UnixNano())

sec := int(math.Max(float64(d/time.Second), 1))
sec = int(math.Min(float64(sec+rand.Intn(9))+1, 60)) // #nosec G404

Expand Down

0 comments on commit 449f4c6

Please sign in to comment.