From 0f1889701544cf2a5dc6237cd5cd50e38f15af94 Mon Sep 17 00:00:00 2001 From: Brian Brazil Date: Mon, 15 Jun 2020 14:14:32 +0100 Subject: [PATCH] Seed RNG to ensure different ICMP ids. (#638) Fixes #632 Signed-off-by: Brian Brazil --- prober/icmp.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/prober/icmp.go b/prober/icmp.go index 83c8736..565988d 100644 --- a/prober/icmp.go +++ b/prober/icmp.go @@ -39,11 +39,12 @@ 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 } @@ -51,7 +52,7 @@ func init() { // 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 { -- 2.25.1