Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: workaround cargo leaking SSL_CERT_FILE issue #615

Merged
merged 3 commits into from
Dec 10, 2022
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
4 changes: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ jobs:
with:
command: doc
args: --all --no-deps
env:
RUSTDOCFLAGS: "-D warnings"


test-examples:
Expand Down Expand Up @@ -181,6 +183,8 @@ jobs:
with:
command: test
args: --manifest-path examples/${{ matrix.example }}/Cargo.toml
env:
RUST_LOG: debug


- name: Test demo script of examples/${{ matrix.example }}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fix:
cargo fix --allow-staged

doc:
cargo doc --all --no-deps
RUSTDOCFLAGS="-D warnings" cargo doc --all --no-deps

guide:
mdbook build
Expand Down
23 changes: 16 additions & 7 deletions examples/raft-kv-memstore/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::BTreeSet;
use std::sync::Arc;
use std::sync::Mutex;
use std::time::Duration;

use openraft::error::AddLearnerError;
use openraft::error::CheckIsLeaderError;
Expand All @@ -19,6 +20,7 @@ use reqwest::Client;
use serde::de::DeserializeOwned;
use serde::Deserialize;
use serde::Serialize;
use tokio::time::timeout;

use crate::ExampleNodeId;
use crate::ExampleRequest;
Expand Down Expand Up @@ -155,23 +157,30 @@ impl ExampleClient {
(t.0, format!("http://{}/{}", target_addr, uri))
};

let resp = if let Some(r) = req {
println!(
let fu = if let Some(r) = req {
tracing::debug!(
">>> client send request to {}: {}",
url,
serde_json::to_string_pretty(&r).unwrap()
);
self.inner.post(url.clone()).json(r)
} else {
println!(">>> client send request to {}", url,);
tracing::debug!(">>> client send request to {}", url,);
self.inner.get(url.clone())
}
.send()
.await
.map_err(|e| RPCError::Network(NetworkError::new(&e)))?;
.send();

let res = timeout(Duration::from_millis(3_000), fu).await;
let resp = match res {
Ok(x) => x.map_err(|e| RPCError::Network(NetworkError::new(&e)))?,
Err(timeout_err) => {
tracing::error!("timeout {} to url: {}", timeout_err, url);
return Err(RPCError::Network(NetworkError::new(&timeout_err)));
}
};

let res: Result<Resp, Err> = resp.json().await.map_err(|e| RPCError::Network(NetworkError::new(&e)))?;
println!(
tracing::debug!(
"<<< client recv reply from {}: {}",
url,
serde_json::to_string_pretty(&res).unwrap()
Expand Down
9 changes: 8 additions & 1 deletion examples/raft-kv-memstore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ pub type ExampleRaft = Raft<ExampleTypeConfig, ExampleNetwork, Arc<ExampleStore>

pub async fn start_example_raft_node(node_id: ExampleNodeId, http_addr: String) -> std::io::Result<()> {
// Create a configuration for the raft instance.
let config = Arc::new(Config::default().validate().unwrap());
let config = Config {
heartbeat_interval: 500,
election_timeout_min: 1500,
election_timeout_max: 3000,
..Default::default()
};

let config = Arc::new(config.validate().unwrap());

// Create a instance of where the Raft data will be stored.
let store = Arc::new(ExampleStore::default());
Expand Down
7 changes: 7 additions & 0 deletions examples/raft-kv-memstore/src/network/raft_network_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,17 @@ impl ExampleNetwork {
let addr = &target_node.addr;

let url = format!("http://{}/{}", addr, uri);

tracing::debug!("send_rpc to url: {}", url);

let client = reqwest::Client::new();

tracing::debug!("client is created for: {}", url);

let resp = client.post(url).json(&req).send().await.map_err(|e| RPCError::Network(NetworkError::new(&e)))?;

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

let res: Result<Resp, Err> = resp.json().await.map_err(|e| RPCError::Network(NetworkError::new(&e)))?;

res.map_err(|e| RPCError::RemoteError(RemoteError::new(target, e)))
Expand Down
11 changes: 10 additions & 1 deletion examples/raft-kv-memstore/tests/cluster/test_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use raft_kv_memstore::start_example_raft_node;
use raft_kv_memstore::store::ExampleRequest;
use raft_kv_memstore::ExampleNodeId;
use tokio::runtime::Runtime;
use tracing_subscriber::EnvFilter;

/// Setup a cluster of 3 nodes.
/// Write to it and read from it.
Expand All @@ -21,6 +22,14 @@ async fn test_cluster() -> anyhow::Result<()> {
// Thus we need a supporting component to provide mapping from node id to node address.
// This is only used by the client. A raft node in this example stores node addresses in its store.

tracing_subscriber::fmt()
.with_target(true)
.with_thread_ids(true)
.with_level(true)
.with_ansi(false)
.with_env_filter(EnvFilter::from_default_env())
.init();

let get_addr = |node_id| {
let addr = match node_id {
1 => "127.0.0.1:21001".to_string(),
Expand Down Expand Up @@ -200,7 +209,7 @@ async fn test_cluster() -> anyhow::Result<()> {
println!("=== change-membership to 3, ");
let _x = client.change_membership(&btreeset! {3}).await?;

tokio::time::sleep(Duration::from_millis(1_000)).await;
tokio::time::sleep(Duration::from_millis(8_000)).await;

println!("=== metrics after change-membership to {{3}}");
let x = client.metrics().await?;
Expand Down
4 changes: 2 additions & 2 deletions openraft/src/core/raft_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1408,8 +1408,8 @@ impl<C: RaftTypeConfig, N: RaftNetworkFactory<C>, S: RaftStorage<C>> RaftCore<C,

if session_id.membership_log_id != self.engine.state.membership_state.effective.log_id {
tracing::warn!(
"membership_log_id changed: msg sent by: {:?}; curr: {}; ignore when ({})",
session_id.membership_log_id,
"membership_log_id changed: msg sent by: {}; curr: {}; ignore when ({})",
session_id.membership_log_id.summary(),
self.engine.state.membership_state.effective.log_id.summary(),
msg
);
Expand Down