From 4490cb6cf7c0306da952ea2611aa39f9de41a51e Mon Sep 17 00:00:00 2001 From: Simon Paitrault Date: Fri, 19 Apr 2024 15:11:44 +0200 Subject: [PATCH] chore: adding logs on channel failure Signed-off-by: Simon Paitrault --- crates/topos-tce/src/app_context/network.rs | 48 ++++++++++++++++----- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/crates/topos-tce/src/app_context/network.rs b/crates/topos-tce/src/app_context/network.rs index acfdb569b..b9b439a87 100644 --- a/crates/topos-tce/src/app_context/network.rs +++ b/crates/topos-tce/src/app_context/network.rs @@ -1,5 +1,7 @@ +use futures::TryFutureExt; use prost::Message; use std::collections::hash_map; +use tokio::sync::mpsc::error::TrySendError; use topos_tce_storage::errors::{InternalStorageError, StorageError}; use tokio::spawn; @@ -50,7 +52,7 @@ impl AppContext { certificate_id ); - if self + match self .tce_cli .get_double_echo_channel() .send(DoubleEchoCommand::Broadcast { @@ -58,14 +60,24 @@ impl AppContext { cert, pending_id, }) + .map_err(TrySendError::from) .await - .is_err() { - error!( - "Unable to send DoubleEchoCommand::Broadcast command \ - to double echo for {}", - certificate_id - ); + Err(TrySendError::Full(_)) => { + error!( + "Unable to send DoubleEchoCommand::Broadcast command \ + to double echo for {}, channel is full", + certificate_id + ); + } + Err(TrySendError::Closed(_)) => { + error!( + "Unable to send DoubleEchoCommand::Broadcast command \ + to double echo for {}, channel is closed", + certificate_id + ); + } + Ok(_) => {} } } @@ -136,15 +148,22 @@ impl AppContext { validator_id = validator_id ); - if let Err(e) = channel + match channel .send(DoubleEchoCommand::Echo { signature: signature.into(), certificate_id, validator_id, }) + .map_err(TrySendError::from) .await { - error!("Unable to pass received Echo message: {:?}", e); + Err(TrySendError::Full(_)) => { + error!("Unable to process Echo message due to DoubleEchoChannel being full"); + } + Err(TrySendError::Closed(_)) => { + error!("Unable to process Echo message due to DoubleEchoChannel being closed"); + } + Ok(_) => {} } } else { error!("Unable to process Echo message due to invalid data"); @@ -181,15 +200,22 @@ impl AppContext { certificate_id = certificate_id, validator_id = validator_id ); - if let Err(e) = channel + match channel .send(DoubleEchoCommand::Ready { signature: signature.into(), certificate_id, validator_id, }) + .map_err(TrySendError::from) .await { - error!("Unable to pass received Ready message: {:?}", e); + Err(TrySendError::Full(_)) => { + error!("Unable to process Ready message due to DoubleEchoChannel being full"); + } + Err(TrySendError::Closed(_)) => { + error!("Unable to process Ready message due to DoubleEchoChannel being closed"); + } + Ok(_) => {} } } else { error!("Unable to process Ready message due to invalid data");