Skip to content

Commit

Permalink
Seed RNG to ensure different ICMP ids. (#638)
Browse files Browse the repository at this point in the history
Fixes #632

Signed-off-by: Brian Brazil <brian.brazil@robustperception.io>
  • Loading branch information
brian-brazil authored Jun 15, 2020
1 parent a289888 commit 0f18897
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions prober/icmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,20 @@ var (
)

func init() {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
// PID is typically 1 when running in a container; in that case, set
// the ICMP echo ID to a random value to avoid potential clashes with
// other blackbox_exporter instances. See #411.
if pid := os.Getpid(); pid == 1 {
icmpID = rand.Intn(1 << 16)
icmpID = r.Intn(1 << 16)
} else {
icmpID = pid & 0xffff
}

// Start the ICMP echo sequence at a random offset to prevent them from
// being in sync when several blackbox_exporter instances are restarted
// at the same time. See #411.
icmpSequence = uint16(rand.Intn(1 << 16))
icmpSequence = uint16(r.Intn(1 << 16))
}

func getICMPSequence() uint16 {
Expand Down

0 comments on commit 0f18897

Please sign in to comment.