Skip to content

Commit

Permalink
Fix retry count
Browse files Browse the repository at this point in the history
Retry count should only count retries, not the number of attempts.
A retry count of 0  should still mean 1 connection attempt.

A retry count of N should mean 1 attempt + N retry attempt
  • Loading branch information
sosthene-nitrokey committed Sep 13, 2024
1 parent 366c3f9 commit 94b8838
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions pkcs11/src/backend/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ impl LoginCtx {
let delay = Duration::from_secs(delay_seconds);

loop {
if retry_count == retry_limit {
error!(
"Retry count exceeded after {retry_limit} attempts, instance is unreachable"
);
return Err(ApiError::InstanceRemoved.into());
}
retry_count += 1;
let api_call_clone = api_call.clone();
match api_call_clone(&instance.config) {
Expand All @@ -271,12 +277,8 @@ impl LoginCtx {
| Err(apis::Error::ResponseError(err @ ResponseContent { status: 503, .. }))
| Err(apis::Error::ResponseError(err @ ResponseContent { status: 412, .. })) => {
instance.bump_failed();
if retry_count == retry_limit {
error!("Retry count exceeded after {retry_limit} attempts, instance is unreachable: {:?}",err.status);
return Err(ApiError::InstanceRemoved.into());
}

warn!("Connection attempt {retry_count} failed: IO error connecting to the instance, {:?}, retrying in {delay_seconds}s", err.status);
warn!("Connection attempt {retry_count} failed: Status error connecting to the instance, {:?}, retrying in {delay_seconds}s", err.status);
thread::sleep(delay);
if let Some(new_conf) = self.get_config_user_mode(&user_mode) {
instance = new_conf;
Expand All @@ -291,11 +293,6 @@ impl LoginCtx {
) =>
{
instance.bump_failed();
if retry_count == retry_limit {
error!("Retry count exceeded after {retry_limit} attempts, instance is unreachable: {err}");
return Err(ApiError::InstanceRemoved.into());
}

warn!("Connection attempt {retry_count} failed: IO error connecting to the instance, {err}, retrying in {delay_seconds}s");
thread::sleep(delay);
if let Some(new_conf) = self.get_config_user_mode(&user_mode) {
Expand Down

0 comments on commit 94b8838

Please sign in to comment.