From faf361875cfe22b2da6e2d66bc965999ea1ef91d Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Thu, 21 Oct 2021 16:10:18 -0300 Subject: [PATCH 1/3] add sleep to `accept_inbound_connections()` --- zebra-network/src/peer_set/initialize.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/zebra-network/src/peer_set/initialize.rs b/zebra-network/src/peer_set/initialize.rs index d36f253f95d..d956f5639d9 100644 --- a/zebra-network/src/peer_set/initialize.rs +++ b/zebra-network/src/peer_set/initialize.rs @@ -350,6 +350,9 @@ where } .instrument(handshaker_span), ); + + // Only one sucesful connection per `MIN_PEER_CONNECTION_INTERVAL` is allowed. + tokio::time::sleep(constants::MIN_PEER_CONNECTION_INTERVAL).await; } } } From fb9f56aa8703f3966cbf393cf84a05527d0949ed Mon Sep 17 00:00:00 2001 From: teor Date: Fri, 22 Oct 2021 08:36:37 +1000 Subject: [PATCH 2/3] Expand docs --- zebra-network/src/peer_set/initialize.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zebra-network/src/peer_set/initialize.rs b/zebra-network/src/peer_set/initialize.rs index d956f5639d9..c0dd3e8d995 100644 --- a/zebra-network/src/peer_set/initialize.rs +++ b/zebra-network/src/peer_set/initialize.rs @@ -351,7 +351,11 @@ where .instrument(handshaker_span), ); - // Only one sucesful connection per `MIN_PEER_CONNECTION_INTERVAL` is allowed. + // Only spawn one inbound connection handshake per `MIN_PEER_CONNECTION_INTERVAL`. + // But clear failed connections as fast as possible. + // + // If there is a flood of connections, this stops Zebra overloading the network with handshake data. + // Most OSes also limit the number of queued inbound connections on a listener port. tokio::time::sleep(constants::MIN_PEER_CONNECTION_INTERVAL).await; } } From 484bb48672687b33063c53915db6ff50e56563e0 Mon Sep 17 00:00:00 2001 From: teor Date: Fri, 22 Oct 2021 08:41:01 +1000 Subject: [PATCH 3/3] Expand comments again --- zebra-network/src/peer_set/initialize.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/zebra-network/src/peer_set/initialize.rs b/zebra-network/src/peer_set/initialize.rs index d9ed37d4ab2..7547e395796 100644 --- a/zebra-network/src/peer_set/initialize.rs +++ b/zebra-network/src/peer_set/initialize.rs @@ -397,7 +397,9 @@ where // // If there is a flood of connections, // this stops Zebra overloading the network with handshake data. - // Most OSes also limit the number of queued inbound connections on a listener port. + // + // Zebra can't control how many queued connections are waiting, + // but most OSes also limit the number of queued inbound connections on a listener port. tokio::time::sleep(constants::MIN_PEER_CONNECTION_INTERVAL).await; } }