Skip to content

Commit 78cca71

Browse files
ysaito1001aws-sdk-rust-ci
authored andcommitted
Ensure cache miss logging works in concurrent setting (#2391)
This commit ensures that logging for cache miss should be displayed properly when multiple threads execute `get_or_load` concurrently. Specifically, the log should be displayed only once for the first thread that succeeds in populating a cache value. Co-authored-by: Yuki Saito <awsaito@amazon.com>
1 parent 1baf47b commit 78cca71

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

aws/rust-runtime/aws-credential-types/src/cache/lazy_caching.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,23 @@ impl ProvideCachedCredentials for LazyCredentialsCache {
106106
.buffer_time
107107
.mul_f64((self.buffer_time_jitter_fraction)());
108108

109+
// Logging for cache miss should be emitted here as opposed to after the call to
110+
// `cache.get_or_load` above. In the case of multiple threads concurrently executing
111+
// `cache.get_or_load`, logging inside `cache.get_or_load` ensures that it is emitted
112+
// only once for the first thread that succeeds in populating a cache value.
113+
info!(
114+
"credentials cache miss occurred; added new AWS credentials (took {:?})",
115+
start_time.elapsed()
116+
);
117+
109118
Ok((credentials, expiry + jitter))
110119
}
111120
// Only instrument the the actual load future so that no span
112121
// is opened if the cache decides not to execute it.
113122
.instrument(span)
114123
})
115124
.await;
116-
info!(
117-
"credentials cache miss occurred; retrieved new AWS credentials (took {:?})",
118-
start_time.elapsed()
119-
);
125+
debug!("loaded credentials");
120126
result
121127
}
122128
})

0 commit comments

Comments
 (0)