Skip to content

Commit 6c5f8f2

Browse files
committed
fix(local): get ServerStatData after push_score
1 parent ff3bf36 commit 6c5f8f2

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

crates/shadowsocks-service/src/local/loadbalancing/ping_balancer.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -823,14 +823,12 @@ impl PingChecker {
823823
ServerType::Udp => self.server.udp_score(),
824824
};
825825

826-
let score = match self.check_delay().await {
826+
let (score, stat_data) = match self.check_delay().await {
827827
Ok(d) => server_score.push_score(Score::Latency(d)).await,
828828
// Penalty
829829
Err(..) => server_score.push_score(Score::Errored).await,
830830
};
831831

832-
let stat_data = server_score.stat_data().await;
833-
834832
if stat_data.fail_rate > 0.5 {
835833
warn!(
836834
"balancer: checked & updated remote {} server {} (score: {}), {:?}",

crates/shadowsocks-service/src/local/loadbalancing/server_data.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ impl ServerScore {
4040
}
4141

4242
/// Append a `Score` into statistic and recalculate score of the server
43-
pub async fn push_score(&self, score: Score) -> u32 {
44-
let updated_score = {
43+
pub async fn push_score(&self, score: Score) -> (u32, ServerStatData) {
44+
let (updated_score, data) = {
4545
let mut stat = self.stat_data.lock().await;
46-
stat.push_score(score)
46+
(stat.push_score(score), stat.data().clone())
4747
};
4848
self.score.store(updated_score, Ordering::Release);
49-
updated_score
49+
(updated_score, data)
5050
}
5151

5252
/// Report request failure of this server, which will eventually records an `Errored` score
53-
pub async fn report_failure(&self) -> u32 {
53+
pub async fn report_failure(&self) -> (u32, ServerStatData) {
5454
self.push_score(Score::Errored).await
5555
}
5656

0 commit comments

Comments
 (0)