Skip to content

Commit 02e2a78

Browse files
committed
Retry period reset logic
1 parent 0a4a099 commit 02e2a78

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/agent/services/lazer_exporter.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ use {
2525
std::{
2626
path::PathBuf,
2727
sync::Arc,
28-
time::Duration,
28+
time::{
29+
Duration,
30+
Instant,
31+
},
2932
},
3033
tokio::{
3134
net::TcpStream,
@@ -115,7 +118,6 @@ struct RelayerSessionTask {
115118

116119
impl RelayerSessionTask {
117120
pub async fn run(&mut self) {
118-
let mut failure_count = 0;
119121
let initial_interval = Duration::from_millis(100);
120122
let max_interval = Duration::from_secs(5);
121123
let mut backoff = ExponentialBackoffBuilder::new()
@@ -124,13 +126,23 @@ impl RelayerSessionTask {
124126
.with_max_elapsed_time(None)
125127
.build();
126128

129+
const FAILURE_RESET_TIME: Duration = Duration::from_secs(300);
130+
let mut first_failure_time = Instant::now();
131+
let mut failure_count = 0;
132+
127133
loop {
128134
match self.run_relayer_connection().await {
129135
Ok(()) => {
130136
tracing::info!("relayer session graceful shutdown");
131137
return;
132138
}
133139
Err(e) => {
140+
if first_failure_time.elapsed() > FAILURE_RESET_TIME {
141+
failure_count = 0;
142+
first_failure_time = Instant::now();
143+
backoff.reset();
144+
}
145+
134146
failure_count += 1;
135147
let next_backoff = backoff.next_backoff().unwrap_or(max_interval);
136148
tracing::error!(

0 commit comments

Comments
 (0)