diff --git a/zenoh/src/net/routing/hat/linkstate_peer/network.rs b/zenoh/src/net/routing/hat/linkstate_peer/network.rs index a4a6841644..3fd9f53420 100644 --- a/zenoh/src/net/routing/hat/linkstate_peer/network.rs +++ b/zenoh/src/net/routing/hat/linkstate_peer/network.rs @@ -18,6 +18,7 @@ use crate::net::runtime::Runtime; use crate::runtime::WeakRuntime; use petgraph::graph::NodeIndex; use petgraph::visit::{VisitMap, Visitable}; +use rand::Rng; use std::convert::TryInto; use vec_map::VecMap; use zenoh_buffers::writer::{DidntWrite, HasWriter}; @@ -498,10 +499,10 @@ impl Network { .is_none() { // random backoff - tokio::time::sleep(std::time::Duration::from_millis( - rand::random::() % 100, - )) - .await; + let sleep_time = std::time::Duration::from_millis( + rand::thread_rng().gen_range(0..100), + ); + tokio::time::sleep(sleep_time).await; runtime.connect_peer(&zid, &locators).await; } }); @@ -622,10 +623,10 @@ impl Network { .is_none() { // random backoff - tokio::time::sleep(std::time::Duration::from_millis( - rand::random::() % 100, - )) - .await; + let sleep_time = std::time::Duration::from_millis( + rand::thread_rng().gen_range(0..100), + ); + tokio::time::sleep(sleep_time).await; runtime.connect_peer(&zid, &locators).await; } }); diff --git a/zenoh/src/net/routing/hat/p2p_peer/gossip.rs b/zenoh/src/net/routing/hat/p2p_peer/gossip.rs index 537f29aeec..8ce3bb4792 100644 --- a/zenoh/src/net/routing/hat/p2p_peer/gossip.rs +++ b/zenoh/src/net/routing/hat/p2p_peer/gossip.rs @@ -16,6 +16,7 @@ use crate::net::protocol::linkstate::{LinkState, LinkStateList}; use crate::net::runtime::Runtime; use crate::runtime::WeakRuntime; use petgraph::graph::NodeIndex; +use rand::Rng; use std::convert::TryInto; use vec_map::VecMap; use zenoh_buffers::writer::{DidntWrite, HasWriter}; @@ -418,10 +419,10 @@ impl Network { .is_none() { // random backoff - tokio::time::sleep(std::time::Duration::from_millis( - rand::random::() % 100, - )) - .await; + let sleep_time = std::time::Duration::from_millis( + rand::thread_rng().gen_range(0..100), + ); + tokio::time::sleep(sleep_time).await; runtime.connect_peer(&zid, &locators).await; } }); diff --git a/zenoh/src/net/routing/hat/router/network.rs b/zenoh/src/net/routing/hat/router/network.rs index 1ee77ae8e2..486e0456ab 100644 --- a/zenoh/src/net/routing/hat/router/network.rs +++ b/zenoh/src/net/routing/hat/router/network.rs @@ -17,6 +17,7 @@ use crate::net::routing::dispatcher::tables::NodeId; use crate::net::runtime::Runtime; use petgraph::graph::NodeIndex; use petgraph::visit::{IntoNodeReferences, VisitMap, Visitable}; +use rand::Rng; use std::convert::TryInto; use vec_map::VecMap; use zenoh_buffers::writer::{DidntWrite, HasWriter}; @@ -501,10 +502,10 @@ impl Network { .is_none() { // random backoff - tokio::time::sleep(std::time::Duration::from_millis( - rand::random::() % 100, - )) - .await; + let sleep_time = std::time::Duration::from_millis( + rand::thread_rng().gen_range(0..100), + ); + tokio::time::sleep(sleep_time).await; runtime.connect_peer(&zid, &locators).await; } }); @@ -625,10 +626,10 @@ impl Network { .is_none() { // random backoff - tokio::time::sleep(std::time::Duration::from_millis( - rand::random::() % 100, - )) - .await; + let sleep_time = std::time::Duration::from_millis( + rand::thread_rng().gen_range(0..100), + ); + tokio::time::sleep(sleep_time).await; runtime.connect_peer(&zid, &locators).await; } });