Skip to content

Commit

Permalink
use exponential backoff in spawn_connection_initializations reconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
borngraced committed Dec 9, 2024
1 parent 26ea297 commit 371af58
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
7 changes: 3 additions & 4 deletions mm2src/kdf_walletconnect/src/connection_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use relay_client::error::ClientError;
use relay_client::websocket::{CloseFrame, ConnectionHandler, PublishedMessage};
use std::sync::Arc;

const RETRY_SECS: f64 = 5.0;
const MAX_BACKOFF: u64 = 60;

pub struct Handler {
Expand Down Expand Up @@ -80,16 +79,16 @@ pub(crate) async fn spawn_connection_initialization(
) {
info!("Initializing WalletConnect connection");
let mut retry_count = 0;
let mut retry_secs = RETRY_SECS;
let mut retry_secs = 10;

while let Err(err) = wc.connect_client().await {
retry_count += 1;
error!(
"Error during initial connection attempt {}: {:?}. Retrying in {retry_secs} seconds...",
retry_count, err
);
Timer::sleep(retry_secs).await;
retry_secs += RETRY_SECS;
Timer::sleep(retry_secs as f64).await;
retry_secs = std::cmp::min(retry_secs * 2, MAX_BACKOFF);
}

// Initialize storage
Expand Down
3 changes: 2 additions & 1 deletion mm2src/kdf_walletconnect/src/session/rpc/settle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use mm2_err_handle::prelude::{MapMmError, MmError, MmResult};
use relay_rpc::domain::Topic;
use relay_rpc::rpc::params::session_settle::SessionSettleRequest;

/// TODO: Finish when implementing KDF as a Wallet.
pub(crate) async fn send_session_settle_request(
_ctx: &WalletConnectCtxImpl,
_session_info: &Session,
Expand Down Expand Up @@ -60,7 +61,7 @@ pub(crate) async fn reply_session_settle_request(
.session_manager
.get_session(topic)
.ok_or(MmError::new(WalletConnectError::SessionError(format!(
"session not foun topic: {topic}"
"session not found topic: {topic}"
))))?;
ctx.session_manager
.storage()
Expand Down

0 comments on commit 371af58

Please sign in to comment.