Skip to content
This repository was archived by the owner on Jul 27, 2022. It is now read-only.

Commit 304620f

Browse files
bors[bot]Devashish Dixit
andauthored
Merge #675
675: Problem: (CRO-643) client-rpc does not retry connections to tendermint r=tomtau a=devashishdxt Solution: Added retry logic in case of I/O failure Sample log message: ``` [2019-12-12T09:00:20Z ERROR client_rpc::server] Initialization error: Unable to connect to websocket RPC at: ws://localhost:26657/websocket => WebSocketError: I/O failure ``` Co-authored-by: Devashish Dixit <devashish@crypto.com>
2 parents 2c51f13 + fb140e6 commit 304620f

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

client-rpc/src/server.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use crate::rpc::sync_rpc::{SyncRpc, SyncRpcImpl};
55
use crate::rpc::transaction_rpc::{TransactionRpc, TransactionRpcImpl};
66
use crate::rpc::wallet_rpc::{WalletRpc, WalletRpcImpl};
77
use std::net::SocketAddr;
8+
use std::thread;
9+
use std::time::Duration;
810

911
use chain_core::init::network::{get_network, get_network_id, init_chain_id};
1012
use chain_core::tx::fee::LinearFee;
@@ -198,7 +200,22 @@ impl Server {
198200
let mut io = IoHandler::new();
199201
let storage = SledStorage::new(&self.storage_dir)?;
200202

201-
let tendermint_client = WebsocketRpcClient::new(&self.websocket_url)?;
203+
let tendermint_client = loop {
204+
match WebsocketRpcClient::new(&self.websocket_url) {
205+
Ok(client) => {
206+
break Ok(client);
207+
}
208+
Err(error) => {
209+
if ErrorKind::InitializationError == error.kind() {
210+
log::error!("{:?}", error);
211+
} else {
212+
break Err(error);
213+
}
214+
}
215+
}
216+
217+
thread::sleep(Duration::from_secs(2));
218+
}?;
202219

203220
self.start_client(&mut io, storage.clone(), tendermint_client.clone())
204221
.unwrap();

0 commit comments

Comments
 (0)