From d99968af8e5c5b533f08a1e1c55c15278c846e76 Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 7 Dec 2023 09:04:21 +1000 Subject: [PATCH 1/2] Silence verbose failed connection logs --- zebra-network/src/peer_set/initialize.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/zebra-network/src/peer_set/initialize.rs b/zebra-network/src/peer_set/initialize.rs index 6b2ae33e34f..c1be1845846 100644 --- a/zebra-network/src/peer_set/initialize.rs +++ b/zebra-network/src/peer_set/initialize.rs @@ -863,8 +863,9 @@ where // Increment the connection count before we spawn the connection. let outbound_connection_tracker = active_outbound_connections.track_connection(); + let outbound_connections = active_outbound_connections.update_count(); debug!( - outbound_connections = ?active_outbound_connections.update_count(), + ?outbound_connections, "opening an outbound peer connection" ); @@ -892,6 +893,7 @@ where candidate, outbound_connector, outbound_connection_tracker, + outbound_connections, peerset_tx, address_book_updater, demand_tx, @@ -1026,6 +1028,7 @@ where #[instrument(skip( outbound_connector, outbound_connection_tracker, + outbound_connections, peerset_tx, address_book_updater, demand_tx @@ -1034,6 +1037,7 @@ async fn dial( candidate: MetaAddr, mut outbound_connector: C, outbound_connection_tracker: ConnectionTracker, + outbound_connections: usize, mut peerset_tx: futures::channel::mpsc::Sender, address_book_updater: tokio::sync::mpsc::Sender, mut demand_tx: futures::channel::mpsc::Sender, @@ -1048,6 +1052,9 @@ where + 'static, C::Future: Send + 'static, { + // The maximum number of open or pending connections before we log an info-level message. + const MAX_CONNECTIONS_FOR_INFO_LOG: usize = 5; + // # Correctness // // To avoid hangs, the dialer must only await: @@ -1076,7 +1083,13 @@ where } // The connection was never opened, or it failed the handshake and was dropped. Err(error) => { - info!(?error, ?candidate.addr, "failed to make outbound connection to peer"); + // Silence verbose info logs in production, but keep logs if the number of connections is low. + // Also silence them completely in tests. + if outbound_connections <= MAX_CONNECTIONS_FOR_INFO_LOG && !cfg!(test) { + info!(?error, ?candidate.addr, "failed to make outbound connection to peer"); + } else { + debug!(?error, ?candidate.addr, "failed to make outbound connection to peer"); + } report_failed(address_book_updater.clone(), candidate).await; // The demand signal that was taken out of the queue to attempt to connect to the From 7a5171489d218bc6f1a4afe2c9d7da3dbb357f92 Mon Sep 17 00:00:00 2001 From: teor Date: Thu, 7 Dec 2023 12:19:42 +1000 Subject: [PATCH 2/2] Update comment and fix formatting --- zebra-network/src/peer_set/initialize.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/zebra-network/src/peer_set/initialize.rs b/zebra-network/src/peer_set/initialize.rs index c1be1845846..fc07a38374d 100644 --- a/zebra-network/src/peer_set/initialize.rs +++ b/zebra-network/src/peer_set/initialize.rs @@ -864,10 +864,7 @@ where // Increment the connection count before we spawn the connection. let outbound_connection_tracker = active_outbound_connections.track_connection(); let outbound_connections = active_outbound_connections.update_count(); - debug!( - ?outbound_connections, - "opening an outbound peer connection" - ); + debug!(?outbound_connections, "opening an outbound peer connection"); // Spawn each handshake or crawl into an independent task, so handshakes can make // progress while crawls are running. @@ -1052,7 +1049,8 @@ where + 'static, C::Future: Send + 'static, { - // The maximum number of open or pending connections before we log an info-level message. + // If Zebra only has a few connections, we log connection failures at info level, + // so users can diagnose and fix the problem. This defines the threshold for info logs. const MAX_CONNECTIONS_FOR_INFO_LOG: usize = 5; // # Correctness