Skip to content

Commit

Permalink
Add connectivity timeout
Browse files Browse the repository at this point in the history
Added a wallet connectivity timeout so long-winded failures can be managed timeously.
  • Loading branch information
hansieodendaal committed Nov 26, 2024
1 parent 321e9ba commit dada390
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 14 additions & 4 deletions base_layer/wallet/src/connectivity_service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use tari_core::base_node::{rpc::BaseNodeWalletRpcClient, sync::rpc::BaseNodeSync
use tokio::{
sync::{mpsc, oneshot, watch},
time,
time::MissedTickBehavior,
time::{timeout, Duration as TokioDuration, MissedTickBehavior},
};

use crate::{
Expand Down Expand Up @@ -392,12 +392,22 @@ impl WalletConnectivityService {
}

async fn try_setup_rpc_pool(&mut self, peer_node_id: NodeId) -> Result<bool, WalletConnectivityError> {
let conn = match self.try_dial_peer(peer_node_id.clone()).await? {
Some(c) => c,
None => {
let dial_timeout = TokioDuration::from_secs(40);
let conn = match timeout(dial_timeout, self.try_dial_peer(peer_node_id.clone())).await {
Ok(Ok(Some(c))) => c,
Ok(Ok(None)) => {
warn!(target: LOG_TARGET, "Could not dial base node peer '{}'", peer_node_id);
return Ok(false);
},
Ok(Err(e)) => return Err(e),
Err(_) => {
return Err(WalletConnectivityError::ConnectivityError(
ConnectivityError::ClientCancelled(format!(
"Could not connect to '{}' in {:?}",
peer_node_id, dial_timeout
)),
));
},
};
debug!(
target: LOG_TARGET,
Expand Down
2 changes: 2 additions & 0 deletions comms/core/src/connectivity/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ pub enum ConnectivityError {
OnlineWaitTimeout(usize),
#[error("Pending dial was cancelled")]
DialCancelled,
#[error("Client cancelled: '{0}'")]
ClientCancelled(String),
}

impl From<ConnectionManagerError> for ConnectivityError {
Expand Down

0 comments on commit dada390

Please sign in to comment.