Skip to content

Commit 03e9e95

Browse files
committed
fix(local): ServerScore push_score maintain compatibility
1 parent 6c5f8f2 commit 03e9e95

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -824,9 +824,9 @@ impl PingChecker {
824824
};
825825

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

832832
if stat_data.fail_rate > 0.5 {

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

+12-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +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, ServerStatData) {
43+
pub async fn push_score(&self, score: Score) -> u32 {
44+
let updated_score = {
45+
let mut stat = self.stat_data.lock().await;
46+
stat.push_score(score)
47+
};
48+
self.score.store(updated_score, Ordering::Release);
49+
updated_score
50+
}
51+
52+
/// Append a `Score` into statistic and recalculate score of the server
53+
pub async fn push_score_fetch_statistic(&self, score: Score) -> (u32, ServerStatData) {
4454
let (updated_score, data) = {
4555
let mut stat = self.stat_data.lock().await;
4656
(stat.push_score(score), stat.data().clone())
@@ -50,7 +60,7 @@ impl ServerScore {
5060
}
5161

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

0 commit comments

Comments
 (0)