Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 2 additions & 35 deletions mm2src/kdf_walletconnect/src/connection_handler.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
use crate::WalletConnectCtxImpl;

use common::executor::Timer;
use common::log::{debug, error, info};
use futures::channel::mpsc::{UnboundedReceiver, UnboundedSender};
use futures::StreamExt;
use common::log::{debug, error};
use futures::channel::mpsc::UnboundedSender;
use relay_client::error::ClientError;
use relay_client::websocket::{CloseFrame, ConnectionHandler, PublishedMessage};

Expand Down Expand Up @@ -67,32 +63,3 @@ impl ConnectionHandler for Handler {
}
}
}

/// Handles unexpected disconnections from WalletConnect relay server.
/// Implements exponential backoff retry mechanism for reconnection attempts.
/// After successful reconnection, resubscribes to previous topics to restore full functionality.
pub(crate) async fn handle_disconnections(
this: &WalletConnectCtxImpl,
mut connection_live_rx: UnboundedReceiver<Option<String>>,
) {
let mut backoff = 1;

while let Some(msg) = connection_live_rx.next().await {
info!("WalletConnect disconnected with message: {msg:?}. Attempting to reconnect...");
loop {
match this.reconnect_and_subscribe().await {
Ok(_) => {
info!("Reconnection process complete.");
backoff = 1;
break;
},
Err(e) => {
error!("Reconnection attempt failed: {:?}. Retrying in {:?}...", e, backoff);
Timer::sleep(backoff as f64).await;
// Exponentially increase backoff, but cap it at MAX_BACKOFF
backoff = std::cmp::min(backoff * 2, MAX_BACKOFF);
},
}
}
}
}
Loading
Loading