Skip to content

Commit

Permalink
Updated raft network implementation in example to return unreachable …
Browse files Browse the repository at this point in the history
…error for connection errors to prevent immediate retries.
  • Loading branch information
undecidedapollo committed Mar 15, 2024
1 parent 1876b7f commit 8c39fc5
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions examples/raft-kv-memstore/src/network/raft_network_impl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use openraft::error::InstallSnapshotError;
use openraft::error::NetworkError;
use openraft::error::RemoteError;
use openraft::error::Unreachable;
use openraft::network::RPCOption;
use openraft::network::RaftNetwork;
use openraft::network::RaftNetworkFactory;
Expand Down Expand Up @@ -41,12 +42,14 @@ impl Network {
let client = reqwest::Client::new();
tracing::debug!("client is created for: {}", url);

let resp = client
.post(url)
.json(&req)
.send()
.await
.map_err(|e| openraft::error::RPCError::Network(NetworkError::new(&e)))?;
let resp = client.post(url).json(&req).send().await.map_err(|e| {
// If the error is a connection error, we return Unreachable so that connection isn't retried
// immediately.
if e.is_connect() {
return openraft::error::RPCError::Unreachable(Unreachable::new(&e));
}
openraft::error::RPCError::Network(NetworkError::new(&e))
})?;

tracing::debug!("client.post() is sent");

Expand Down

0 comments on commit 8c39fc5

Please sign in to comment.