diff --git a/src/client.rs b/src/client.rs index 7e4e626..196839c 100644 --- a/src/client.rs +++ b/src/client.rs @@ -53,7 +53,9 @@ macro_rules! impl_inner_call { return res; }, Err(e) => { - let failed_attempts = errors.len() + 1; + errors.push(e); + let e = errors[errors.len() - 1]; + let failed_attempts = errors.len(); if retries_exhausted(failed_attempts, $self.config.retry()) { warn!("call '{}' failed after {} attempts", stringify!($name), failed_attempts); @@ -62,8 +64,6 @@ macro_rules! impl_inner_call { warn!("call '{}' failed with {}, retry: {}/{}", stringify!($name), e, failed_attempts, $self.config.retry()); - errors.push(e); - // Only one thread will try to recreate the client getting the write lock, // other eventual threads will get Err and will block at the beginning of // previous loop when trying to read() @@ -77,7 +77,9 @@ macro_rules! impl_inner_call { break; }, Err(e) => { - let failed_attempts = errors.len() + 1; + errors.push(e); + let e = errors[errors.len() - 1]; + let failed_attempts = errors.len(); if retries_exhausted(failed_attempts, $self.config.retry()) { warn!("re-creating client failed after {} attempts", failed_attempts); @@ -85,8 +87,6 @@ macro_rules! impl_inner_call { } warn!("re-creating client failed with {}, retry: {}/{}", e, failed_attempts, $self.config.retry()); - - errors.push(e); } } }