Skip to content

Commit 5706061

Browse files
committed
fix: ignore unreachable endpoints after max attempts
1 parent 2fa538e commit 5706061

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

src/plugins/manager.rs

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::collections::BTreeMap;
22
use std::sync::Mutex;
33
use std::time;
44

5+
use ahash::HashSet;
56
use ansi_term::Style;
67
use lazy_static::lazy_static;
78
use rand::Rng;
@@ -103,6 +104,7 @@ async fn worker(plugin: &dyn Plugin, session: Arc<Session>) {
103104

104105
let timeout = time::Duration::from_millis(session.options.timeout);
105106
let retry_time: time::Duration = time::Duration::from_millis(session.options.retry_time);
107+
let mut unreachables: HashSet<String> = HashSet::default();
106108

107109
while let Ok(creds) = session.recv_new_credentials().await {
108110
if session.is_stop() {
@@ -126,36 +128,43 @@ async fn worker(plugin: &dyn Plugin, session: Arc<Session>) {
126128

127129
attempt += 1;
128130

129-
match plugin.attempt(&creds, timeout).await {
130-
Err(err) => {
131-
errors += 1;
132-
if attempt < session.options.retries {
133-
log::debug!(
134-
"[{}] attempt {}/{}: {}",
135-
&creds.target,
136-
attempt,
137-
session.options.retries,
138-
err
139-
);
140-
std::thread::sleep(retry_time);
141-
continue;
142-
} else {
143-
log::error!(
144-
"[{}] attempt {}/{}: {}",
145-
&creds.target,
146-
attempt,
147-
session.options.retries,
148-
err
149-
);
131+
// skip attempt if we had enough failures from this specific target
132+
if !unreachables.contains(&creds.target) {
133+
match plugin.attempt(&creds, timeout).await {
134+
Err(err) => {
135+
errors += 1;
136+
if attempt < session.options.retries {
137+
log::debug!(
138+
"[{}] attempt {}/{}: {}",
139+
&creds.target,
140+
attempt,
141+
session.options.retries,
142+
err
143+
);
144+
std::thread::sleep(retry_time);
145+
continue;
146+
} else {
147+
// add this target to the list of unreachable in order to avoi
148+
// pointless attempts
149+
unreachables.insert(creds.target.clone());
150+
151+
log::error!(
152+
"[{}] attempt {}/{}: {}",
153+
&creds.target,
154+
attempt,
155+
session.options.retries,
156+
err
157+
);
158+
}
150159
}
151-
}
152-
Ok(loot) => {
153-
// do we have new loot?
154-
if let Some(loot) = loot {
155-
session.add_loot(loot).await.unwrap();
160+
Ok(loot) => {
161+
// do we have new loot?
162+
if let Some(loot) = loot {
163+
session.add_loot(loot).await.unwrap();
164+
}
156165
}
157-
}
158-
};
166+
};
167+
}
159168

160169
break;
161170
}

0 commit comments

Comments
 (0)