hunter/worker: limit token_tries

This commit is contained in:
Astro 2023-08-09 02:05:53 +02:00
parent 0a3508087e
commit 3937947f94
1 changed files with 6 additions and 0 deletions

View File

@ -295,12 +295,16 @@ async fn open_stream(
metrics::decrement_gauge!("hunter_requests", 1.0, "type" => "stream_open");
let mut prev_token: Option<String> = None;
let mut token_tries = 0;
while let Err(StreamError::HttpStatus(StatusCode::UNAUTHORIZED)) = &stream {
if let Some(invalid_token) = prev_token {
// If we tried with a token before but it's Unauthorized, delete it.
tracing::warn!("Deleting invalid token for host {}: {}", host, invalid_token);
let _ = db.delete_token(&host, &invalid_token).await;
}
if token_tries > 3 {
break;
}
let token = db.get_token(&host).await
.expect("db.get_token()");
@ -313,7 +317,9 @@ async fn open_stream(
tracing::info!("No working token for {}", host);
break;
}
prev_token = token;
token_tries += 1;
}
if let Err(e) = &stream {