From fdcff18e6ffb4341b08a428e36c15aa6c321e8a9 Mon Sep 17 00:00:00 2001 From: zonyitoo Date: Wed, 19 Jun 2024 23:49:32 +0800 Subject: [PATCH] fix(local-online-config): wrong Server source of OnlineConfig loader FATAL: This will cause PingBalancer adds OnlineConfig servers every update_intervals and never replaces them, which will eventually cause OOM. --- crates/shadowsocks-service/src/config.rs | 9 +++++++-- .../src/local/loadbalancing/ping_balancer.rs | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/shadowsocks-service/src/config.rs b/crates/shadowsocks-service/src/config.rs index 5301ebdf..cc40d81a 100644 --- a/crates/shadowsocks-service/src/config.rs +++ b/crates/shadowsocks-service/src/config.rs @@ -1864,6 +1864,11 @@ impl Config { } } + let server_source = match config_type { + ConfigType::Local | ConfigType::Server | ConfigType::Manager => ServerSource::Configuration, + ConfigType::OnlineConfig => ServerSource::OnlineConfig, + }; + // Standard config // Server match (config.server, config.server_port, config.password, &config.method) { @@ -1906,7 +1911,7 @@ impl Config { }; let mut nsvr = ServerConfig::new(addr, password, method); - nsvr.set_source(ServerSource::Configuration); + nsvr.set_source(server_source); nsvr.set_mode(global_mode); if let Some(ref p) = config.plugin { @@ -2026,7 +2031,7 @@ impl Config { }; let mut nsvr = ServerConfig::new(addr, password, method); - nsvr.set_source(ServerSource::Configuration); + nsvr.set_source(server_source); // Extensible Identity Header, Users if let Some(users) = svr.users { diff --git a/crates/shadowsocks-service/src/local/loadbalancing/ping_balancer.rs b/crates/shadowsocks-service/src/local/loadbalancing/ping_balancer.rs index 8dc9a8b1..0c715f69 100644 --- a/crates/shadowsocks-service/src/local/loadbalancing/ping_balancer.rs +++ b/crates/shadowsocks-service/src/local/loadbalancing/ping_balancer.rs @@ -741,6 +741,14 @@ impl PingBalancer { } } + trace!( + "ping balancer going to replace {} servers (total: {}) with {} servers, sources: {:?}", + old_context.servers.len() - old_servers.len(), + old_context.servers.len(), + servers.len(), + replace_server_sources + ); + let mut servers = servers .into_iter() .map(|s| { @@ -763,6 +771,8 @@ impl PingBalancer { ))); } + trace!("ping balancer merged {} new servers", servers.len()); + let (shared_context, task_abortable) = PingBalancerContext::new( servers, old_context.context.clone(),