Skip to content

Commit 0b5d6be

Browse files
authored
feat: don't log broken pipe error on server by default (#548)
* feat: don't log broken pipe error on server by default * fix ci fail on volo-http ws * fix self test script on macOS
1 parent 5a6018b commit 0b5d6be

File tree

15 files changed

+811
-717
lines changed

15 files changed

+811
-717
lines changed

Cargo.lock

+731-682
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+10-10
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ chrono = { version = "0.4", default-features = false, features = [
4848
"clock",
4949
] }
5050
clap = "4"
51-
colored = "2"
51+
colored = "3"
5252
cookie = "0.18"
5353
cookie_store = "0.21"
5454
dashmap = "6"
55-
dirs = "5"
55+
dirs = "6"
5656
faststr = { version = "0.2.21", features = ["serde"] }
5757
futures = "0.3"
5858
futures-util = "0.3"
5959
flate2 = "1"
60-
git2 = { version = "0.19", default-features = false }
61-
governor = "0.7"
60+
git2 = { version = "0.20", default-features = false }
61+
governor = "0.8"
6262
h2 = "0.4"
6363
heck = "0.5"
6464
hex = "0.4"
@@ -70,7 +70,7 @@ hyper = "1"
7070
hyper-timeout = "0.5"
7171
hyper-util = "0.1"
7272
ipnet = "2"
73-
itertools = "0.13"
73+
itertools = "0.14"
7474
itoa = "1"
7575
libc = "0.2"
7676
linkedbytes = "0.1"
@@ -85,7 +85,7 @@ mockall_double = "0.3"
8585
multer = "3"
8686
mur3 = "0.1"
8787
nix = "0.29"
88-
nom = "7"
88+
nom = "8"
8989
normpath = "1"
9090
num_enum = "0.7"
9191
once_cell = "1"
@@ -97,7 +97,7 @@ pin-project = "1"
9797
pretty_env_logger = "0.5"
9898
proc-macro2 = "1"
9999
quote = "1"
100-
rand = "0.8"
100+
rand = "0.9"
101101
regex = "1"
102102
reqwest = "0.12"
103103
run_script = "0.11"
@@ -112,7 +112,7 @@ simdutf8 = "0.1"
112112
socket2 = "0.5"
113113
sonic-rs = "0.3"
114114
syn = "2"
115-
sysinfo = "0.32"
115+
sysinfo = "0.33"
116116
tempfile = "3"
117117
thiserror = "2"
118118
tokio = "1"
@@ -139,8 +139,8 @@ tokio-rustls = "0.26"
139139
native-tls = "0.2"
140140
tokio-native-tls = "0.3"
141141

142-
tungstenite = "0.24"
143-
tokio-tungstenite = "0.24"
142+
tungstenite = "0.26"
143+
tokio-tungstenite = "0.26"
144144

145145
[profile.release]
146146
opt-level = 3

benchmark/src/perf/cpu.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub async fn record_usage(cpu_usage_list: &mut Vec<f32>, cancel: CancellationTok
8181
loop {
8282
tokio::select! {
8383
_ = tokio::time::sleep(DEFAULT_INTERVAL) => {
84-
system.refresh_processes_specifics(sysinfo::ProcessesToUpdate::Some(&[pid]), true, ProcessRefreshKind::new().with_cpu());
84+
system.refresh_processes_specifics(sysinfo::ProcessesToUpdate::Some(&[pid]), true, ProcessRefreshKind::nothing().with_cpu());
8585
let cpu_usage = system
8686
.process(pid)
8787
.unwrap()

benchmark/src/perf/mem.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub async fn record_usage(mem_usage_list: &mut Vec<u64>, cancel: CancellationTok
5353
loop {
5454
tokio::select! {
5555
_ = tokio::time::sleep(DEFAULT_INTERVAL) => {
56-
system.refresh_processes_specifics(sysinfo::ProcessesToUpdate::Some(&[pid]), true, ProcessRefreshKind::new().with_memory());
56+
system.refresh_processes_specifics(sysinfo::ProcessesToUpdate::Some(&[pid]), true, ProcessRefreshKind::nothing().with_memory());
5757
let mem_usage = system
5858
.process(pid)
5959
.unwrap()

scripts/volo-cli-test.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ escape_tmp_dir() {
3434

3535
init() {
3636
export VOLO_DIR="$PWD"
37-
echo_command cargo build -p volo-cli -j `nproc`
37+
echo_command cargo build -p volo-cli
3838
export VOLO_CLI="$PWD/target/debug/volo"
3939
trap 'echo "Failed to run $LINENO: $BASH_COMMAND (exit code: $?)" && exit 1' ERR
4040
}
@@ -68,7 +68,7 @@ thrift_test() {
6868

6969
echo_command "${VOLO_CLI}" init thrift-test "${idl_path}"
7070
patch_cargo_toml
71-
echo_command cargo build -j `nproc`
71+
echo_command cargo build
7272

7373
escape_tmp_dir
7474
}
@@ -81,7 +81,7 @@ grpc_test() {
8181

8282
echo_command "${VOLO_CLI}" init --includes "${idl_dir}" grpc-test "${idl_path}"
8383
patch_cargo_toml
84-
echo_command cargo build -j `nproc`
84+
echo_command cargo build
8585

8686
escape_tmp_dir
8787
}
@@ -91,7 +91,7 @@ http_test() {
9191

9292
echo_command "${VOLO_CLI}" http init http-test
9393
patch_cargo_toml
94-
echo_command cargo build -j `nproc`
94+
echo_command cargo build
9595

9696
escape_tmp_dir
9797
}

volo-build/src/util.rs

+1
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ mod outer {
223223

224224
use anyhow::bail;
225225

226+
#[allow(dead_code)]
226227
pub fn get_repo_latest_commit_id(repo: &str, r#ref: &str) -> anyhow::Result<String> {
227228
let commit_list = match Command::new("git")
228229
.arg("ls-remote")

volo-http/src/server/utils/ws.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -765,14 +765,14 @@ mod websocket_tests {
765765
let (mut ws_stream, _) =
766766
run_ws_handler(test_helpers::to_service(handler), None, 25231).await;
767767

768-
let input = Message::Text("foobar".to_owned());
768+
let input = Message::Text("foobar".into());
769769
ws_stream.send(input.clone()).await.unwrap();
770770
let output = ws_stream.next().await.unwrap().unwrap();
771771
assert_eq!(input, output);
772772

773-
let input = Message::Ping("foobar".to_owned().into_bytes());
773+
let input = Message::Ping("foobar".into());
774774
ws_stream.send(input).await.unwrap();
775775
let output = ws_stream.next().await.unwrap().unwrap();
776-
assert_eq!(output, Message::Pong("foobar".to_owned().into_bytes()));
776+
assert_eq!(output, Message::Pong("foobar".into()));
777777
}
778778
}

volo-thrift/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "volo-thrift"
3-
version = "0.10.6"
3+
version = "0.10.7"
44
edition.workspace = true
55
homepage.workspace = true
66
repository.workspace = true

volo-thrift/src/transport/multiplex/server.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,20 @@ pub async fn serve<Svc, Req, Resp, E, D>(
6161
)
6262
.await
6363
{
64+
stat_tracer.iter().for_each(|f| f(&cx));
65+
if let ThriftException::Transport(te) = &e {
66+
if volo::util::server_remote_error::is_remote_closed_error(te.io_error())
67+
&& !volo::util::server_remote_error::remote_closed_error_log_enabled()
68+
{
69+
return;
70+
}
71+
}
6472
// log it
6573
error!(
6674
"[VOLO] server send response error: {:?}, cx: \
6775
{:?}, peer_addr: {:?}",
6876
e, cx, peer_addr
6977
);
70-
stat_tracer.iter().for_each(|f| f(&cx));
7178
return;
7279
}
7380
stat_tracer.iter().for_each(|f| f(&cx));
@@ -94,12 +101,21 @@ pub async fn serve<Svc, Req, Resp, E, D>(
94101
.encode::<DummyMessage, ServerContext>(&mut cx, msg)
95102
.await
96103
{
104+
stat_tracer.iter().for_each(|f| f(&cx));
105+
if let ThriftException::Transport(te) = &e {
106+
if volo::util::server_remote_error::is_remote_closed_error(te.io_error())
107+
&& !volo::util::server_remote_error::remote_closed_error_log_enabled()
108+
{
109+
return;
110+
}
111+
}
97112
// log it
98113
error!(
99114
"[VOLO] server send error error: {:?}, cx: {:?}, \
100115
peer_addr: {:?}",
101116
e, cx, peer_addr
102117
);
118+
return;
103119
}
104120
stat_tracer.iter().for_each(|f| f(&cx));
105121
return;

volo-thrift/src/transport/pingpong/server.rs

+8
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ pub async fn serve<Svc, Req, Resp, E, D, SP>(
108108
.instrument(span_provider.on_encode(tracing_cx))
109109
.await
110110
{
111+
if let ThriftException::Transport(te) = &e {
112+
if volo::util::server_remote_error::is_remote_closed_error(te.io_error())
113+
&& !volo::util::server_remote_error::remote_closed_error_log_enabled()
114+
{
115+
stat_tracer.iter().for_each(|f| f(&cx));
116+
return Err(());
117+
}
118+
}
111119
error!(
112120
"[VOLO] server send response error: {:?}, cx: {:?}, \
113121
peer_addr: {:?}",

volo/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "volo"
3-
version = "0.10.4"
3+
version = "0.10.5"
44
edition.workspace = true
55
homepage.workspace = true
66
repository.workspace = true

volo/src/loadbalance/consistent_hash.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -465,12 +465,12 @@ mod tests {
465465

466466
async fn consistent_hash_balance_tests() {
467467
// TODO: Using standard deviation to evaluate load balancing is better?
468-
let mut rng = rand::thread_rng();
468+
let mut rng = rand::rng();
469469
let mut instances = vec![];
470470
for _ in 0..50 {
471-
let w = rng.gen_range(10..=100);
472-
let sub_net = rng.gen_range(0..=255);
473-
let port = rng.gen_range(1000..=65535);
471+
let w = rng.random_range(10..=100);
472+
let sub_net = rng.random_range(0..=255);
473+
let port = rng.random_range(1000..=65535);
474474
instances.push(new_instance(format!("172.17.0.{}:{}", sub_net, port), w));
475475
instances.push(new_instance(format!("192.168.32.{}:{}", sub_net, port), w));
476476
}
@@ -508,9 +508,9 @@ mod tests {
508508
virtual_factor: 100,
509509
weighted: true,
510510
};
511-
let mut rng = rand::thread_rng();
511+
let mut rng = rand::rng();
512512
for i in 0..30 {
513-
let w = rng.gen_range(10..=100);
513+
let w = rng.random_range(10..=100);
514514
instances.push(new_instance(format!("127.0.0.1:{}", i), w));
515515
}
516516
let discovery = StaticDiscover::new(instances.clone());
@@ -519,7 +519,7 @@ mod tests {
519519
let virtual_nodes = lb.build_weighted_instances(instances.clone()).virtual_nodes;
520520
let virtual_nodes: BTreeSet<_> = virtual_nodes.into_iter().collect();
521521

522-
let remove_index = rng.gen_range(0..instances.len());
522+
let remove_index = rng.random_range(0..instances.len());
523523
let _remove_instance = instances.remove(remove_index);
524524
let new_virtual_nodes = lb.build_weighted_instances(instances.clone()).virtual_nodes;
525525
for node in new_virtual_nodes {

volo/src/loadbalance/random.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ use crate::{
1212
};
1313

1414
#[inline]
15-
fn pick_one(weight: isize, iter: &[Arc<Instance>]) -> Option<(usize, Arc<Instance>)> {
15+
fn pick_one(weight: usize, iter: &[Arc<Instance>]) -> Option<(usize, Arc<Instance>)> {
1616
if weight == 0 {
1717
return None;
1818
}
19-
let mut weight = rand::thread_rng().gen_range(0..weight);
19+
let mut weight = rand::rng().random_range(0..weight) as isize;
2020
for (offset, instance) in iter.iter().enumerate() {
2121
weight -= instance.weight as isize;
2222
if weight <= 0 {
@@ -29,7 +29,7 @@ fn pick_one(weight: isize, iter: &[Arc<Instance>]) -> Option<(usize, Arc<Instanc
2929
#[derive(Debug)]
3030
pub struct InstancePicker {
3131
shared_instances: Arc<WeightedInstances>,
32-
sum_of_weights: isize,
32+
sum_of_weights: usize,
3333
owned_instances: OnceCell<Vec<Arc<Instance>>>,
3434
last_pick: Option<(usize, Arc<Instance>)>,
3535
}
@@ -54,7 +54,7 @@ impl Iterator for InstancePicker {
5454
.get_or_init(|| shared_instances.to_vec());
5555
let owned = self.owned_instances.get_mut().unwrap();
5656

57-
self.sum_of_weights -= last_pick.weight as isize;
57+
self.sum_of_weights -= last_pick.weight as usize;
5858
owned.remove(*last_offset);
5959

6060
(*last_offset, *last_pick) = pick_one(self.sum_of_weights, owned)?;
@@ -67,15 +67,15 @@ impl Iterator for InstancePicker {
6767

6868
#[derive(Debug, Clone)]
6969
struct WeightedInstances {
70-
sum_of_weights: isize,
70+
sum_of_weights: usize,
7171
instances: Vec<Arc<Instance>>,
7272
}
7373

7474
impl From<Vec<Arc<Instance>>> for WeightedInstances {
7575
fn from(instances: Vec<Arc<Instance>>) -> Self {
7676
let sum_of_weights = instances
7777
.iter()
78-
.fold(0, |lhs, rhs| lhs + rhs.weight as isize);
78+
.fold(0, |lhs, rhs| lhs + rhs.weight as usize);
7979
Self {
8080
instances,
8181
sum_of_weights,

volo/src/util/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
pub mod buf_reader;
22

3+
// used internally.
4+
#[doc(hidden)]
5+
pub mod server_remote_error;
6+
37
use std::{borrow::Borrow, fmt, sync::Arc};
48

59
#[derive(Debug, PartialEq, PartialOrd, Eq, Hash)]

volo/src/util/server_remote_error.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//! This module is used internally.
2+
3+
pub const ENABLE_REMOTE_CLOSED_ERROR_LOG_ENV_KEY: &str = "VOLO_ENABLE_REMOTE_CLOSED_ERROR_LOG";
4+
5+
pub static ENABLE_REMOTE_CLOSE_ERROR_LOG: std::sync::LazyLock<bool> =
6+
std::sync::LazyLock::new(|| std::env::var(ENABLE_REMOTE_CLOSED_ERROR_LOG_ENV_KEY).is_ok());
7+
8+
pub fn remote_closed_error_log_enabled() -> bool {
9+
*ENABLE_REMOTE_CLOSE_ERROR_LOG
10+
}
11+
12+
pub fn is_remote_closed_error(err: &std::io::Error) -> bool {
13+
err.kind() == std::io::ErrorKind::ConnectionReset
14+
|| err.kind() == std::io::ErrorKind::ConnectionAborted
15+
|| err.kind() == std::io::ErrorKind::BrokenPipe
16+
}

0 commit comments

Comments
 (0)