From ad5f5ff24a6c53d0b6475e5e9e7f69a1cd69b497 Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Thu, 21 Oct 2021 21:35:34 -0300 Subject: [PATCH] Rate limit the amount of inbound connections (#2928) * add sleep to `accept_inbound_connections()` * Expand docs * Expand comments again Co-authored-by: teor --- zebra-network/src/peer_set/initialize.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/zebra-network/src/peer_set/initialize.rs b/zebra-network/src/peer_set/initialize.rs index aa3819ed..68312f1a 100644 --- a/zebra-network/src/peer_set/initialize.rs +++ b/zebra-network/src/peer_set/initialize.rs @@ -415,6 +415,16 @@ where .instrument(handshaker_span), ); } + + // Only spawn one inbound connection handshake per `MIN_PEER_CONNECTION_INTERVAL`. + // But clear out failed connections as fast as possible. + // + // If there is a flood of connections, + // this stops Zebra overloading the network with handshake data. + // + // 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; } } }