Skip to content

Commit

Permalink
Ensure cache miss logging works in concurrent setting (smithy-lang#2391)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ysaito1001 and ysaito1001 authored Feb 17, 2023
1 parent 52b07c2 commit b9f8090
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions aws/rust-runtime/aws-credential-types/src/cache/lazy_caching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,23 @@ impl ProvideCachedCredentials for LazyCredentialsCache {
.buffer_time
.mul_f64((self.buffer_time_jitter_fraction)());

// Logging for cache miss should be emitted here as opposed to after the call to
// `cache.get_or_load` above. In the case of multiple threads concurrently executing
// `cache.get_or_load`, logging inside `cache.get_or_load` ensures that it is emitted
// only once for the first thread that succeeds in populating a cache value.
info!(
"credentials cache miss occurred; added new AWS credentials (took {:?})",
start_time.elapsed()
);

Ok((credentials, expiry + jitter))
}
// Only instrument the the actual load future so that no span
// is opened if the cache decides not to execute it.
.instrument(span)
})
.await;
info!(
"credentials cache miss occurred; retrieved new AWS credentials (took {:?})",
start_time.elapsed()
);
debug!("loaded credentials");
result
}
})
Expand Down

0 comments on commit b9f8090

Please sign in to comment.