Skip to content

Commit

Permalink
log(connect_to_peers): reduce log-noise on failed outgoing connections
Browse files Browse the repository at this point in the history
Previously, the `error` log-level was used when outgoing connections
failed. With this commit, it is either `warn` or `info`. `warn` if the
user has explicitly requested to be connected to this peer in the CLI
arguments. And `info` if they have not, which would indicate this
connection is being made through peer-discovery.
  • Loading branch information
Sword-Smith committed Jan 6, 2025
1 parent 8fb1a1b commit 8eb547c
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/connect_to_peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,23 @@ pub(crate) async fn call_peer(
main_to_peer_task_rx: broadcast::Receiver<MainToPeerTask>,
peer_task_to_main_tx: mpsc::Sender<PeerTaskToMain>,
own_handshake_data: HandshakeData,
distance: u8,
peer_distance: u8,
) {
let state_clone = state.clone();
let peer_task_to_main_tx_clone = peer_task_to_main_tx.clone();
let panic_result = std::panic::AssertUnwindSafe(async {
debug!("Attempting to initiate connection to {peer_address}");
match tokio::net::TcpStream::connect(peer_address).await {
Err(e) => {
warn!("Failed to establish connection to {peer_address}: {}", e);
let msg = format!("Failed to establish TCP connection to {peer_address}: {e}");
if peer_distance == 1 {
// outgoing connection to peer of distance 1 means user has
// requested a connection to this peer through CLI
// arguments, and should be warned if this fails.
warn!("{msg}");
} else {
info!("{msg}");
}
}
Ok(stream) => {
match call_peer_inner(
Expand All @@ -334,12 +342,22 @@ pub(crate) async fn call_peer(
main_to_peer_task_rx,
peer_task_to_main_tx,
&own_handshake_data,
distance,
peer_distance,
)
.await
{
Ok(()) => (),
Err(e) => error!("An error occurred: {}. Connection closing", e),
Err(e) => {
let msg = format!("{e}. Failed to establish connection.");
// outgoing connection to peer of distance 1 means user has
// requested a connection to this peer through CLI
// arguments, and should be warned if this fails.
if peer_distance == 1 {
warn!("{msg}");
} else {
info!("{msg}");
}
}
}
}
};
Expand Down

0 comments on commit 8eb547c

Please sign in to comment.