Skip to content

Commit 2652016

Browse files
Improve logging in case of call failure
Previously, we were logging the retry attempt before we even evaluated whether or not we are going to retry again. Instead, we now compute the number of failed attempts and either log and bail from the function or inform the user that we are going to retry the call. We also include the name of the failed call and the reason why it failed in case we are retrying it. Once we have exhausted the the number of retries, we return all errors anyway so there is no reason to log them. It is up to the caller to perform error handling.
1 parent 23c2004 commit 2652016

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/client.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,17 @@ macro_rules! impl_inner_call {
5252
return res;
5353
},
5454
Err(e) => {
55-
warn!("call retry:{}/{} {:?}", errors.len() + 1 , $self.config.retry(), e);
56-
errors.push(e);
57-
if errors.len() as u8 > $self.config.retry() {
55+
let failed_attempts = (errors.len() + 1) as u8;
56+
57+
if failed_attempts > $self.config.retry() {
58+
warn!("call '{}' failed after {} attempts", stringify!($name), failed_attempts);
5859
return Err(Error::AllAttemptsErrored(errors));
5960
}
6061

62+
warn!("call '{}' failed with {}, retry: {}/{}", stringify!($name), e, failed_attempts, $self.config.retry());
63+
64+
errors.push(e);
65+
6166
// Only one thread will try to recreate the client getting the write lock,
6267
// other eventual threads will get Err and will block at the beginning of
6368
// previous loop when trying to read()

0 commit comments

Comments
 (0)