Skip to content

Commit a5084f3

Browse files
committed
fix backoff calculation
After 64 tries, the integer would overflow and retries would happen immediately after zero seconds instead of 8.
1 parent b8bc2b6 commit a5084f3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/state.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ impl AppState {
134134
}
135135

136136
pub fn get_backoff_duration(&self) -> Duration {
137-
let seconds = std::cmp::min(2u64.pow(self.connect_tries.saturating_sub(1)), 8);
137+
let clamped_tries = std::cmp::min(self.connect_tries, 3);
138+
let seconds = 2u64.pow(clamped_tries);
138139
Duration::from_secs(seconds)
139140
}
140141

0 commit comments

Comments
 (0)