Skip to content

Commit 166f0e2

Browse files
ysaito1001jdisanti
andauthored
Cap the max jitter fraction for cache refresh buffer time to 0.5 (#3402)
## Description Via code inspection, we have identified that there is a potential bug in `DEFAULT_BUFFER_TIME_JITTER_FRACTION`. Specifically, if the fraction happens to be set to 1.0, we end up not respecting the buffer time for cache refresh (see diagrams in #2335). This PR will cap the max fraction value to 0.5 to avoid the problem. ## Checklist <!--- If a checkbox below is not applicable, then please DELETE it rather than leaving it unchecked --> - [x] I have updated `CHANGELOG.next.toml` if I made changes to the smithy-rs codegen or runtime crates - [x] I have updated `CHANGELOG.next.toml` if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --------- Co-authored-by: John DiSanti <[email protected]>
1 parent df1103d commit 166f0e2

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

CHANGELOG.next.toml

+12
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,15 @@ was added.
8686
references = ["smithy-rs#3322"]
8787
meta = { "breaking" = false, "bug" = true, "tada" = false }
8888
author = "Velfi"
89+
90+
[[smithy-rs]]
91+
message = "Cap the maximum jitter fraction for identity cache refresh buffer time to 0.5. It was previously 1.0, and if the fraction was randomly set to 1.0, it was equivalent to disregarding the buffer time for cache refresh."
92+
references = ["smithy-rs#3402"]
93+
meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "client" }
94+
author = "ysaito1001"
95+
96+
[[aws-sdk-rust]]
97+
message = "Cap the maximum jitter fraction for credentials cache refresh buffer time to 0.5. It was previously 1.0, and if the fraction was randomly set to 1.0, it was equivalent to disregarding the buffer time for cache refresh."
98+
references = ["smithy-rs#3402"]
99+
meta = { "breaking" = false, "tada" = false, "bug" = true }
100+
author = "ysaito1001"

rust-runtime/aws-smithy-runtime/src/client/identity/cache/lazy.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use tracing::Instrument;
2424
const DEFAULT_LOAD_TIMEOUT: Duration = Duration::from_secs(5);
2525
const DEFAULT_EXPIRATION: Duration = Duration::from_secs(15 * 60);
2626
const DEFAULT_BUFFER_TIME: Duration = Duration::from_secs(10);
27-
const DEFAULT_BUFFER_TIME_JITTER_FRACTION: fn() -> f64 = fastrand::f64;
27+
const DEFAULT_BUFFER_TIME_JITTER_FRACTION: fn() -> f64 = || fastrand::f64() * 0.5;
2828

2929
/// Builder for lazy identity caching.
3030
#[derive(Default, Debug)]
@@ -86,7 +86,7 @@ impl LazyCacheBuilder {
8686
/// For example, if the identity are expiring in 15 minutes, and the buffer time is 10 seconds,
8787
/// then any requests made after 14 minutes and 50 seconds will load a new identity.
8888
///
89-
/// Note: random jitter value between [0.0, 1.0] is multiplied to this buffer time.
89+
/// Note: random jitter value between [0.0, 0.5] is multiplied to this buffer time.
9090
///
9191
/// Defaults to 10 seconds.
9292
pub fn buffer_time(mut self, buffer_time: Duration) -> Self {
@@ -99,7 +99,7 @@ impl LazyCacheBuilder {
9999
/// For example, if the identity are expiring in 15 minutes, and the buffer time is 10 seconds,
100100
/// then any requests made after 14 minutes and 50 seconds will load a new identity.
101101
///
102-
/// Note: random jitter value between [0.0, 1.0] is multiplied to this buffer time.
102+
/// Note: random jitter value between [0.0, 0.5] is multiplied to this buffer time.
103103
///
104104
/// Defaults to 10 seconds.
105105
pub fn set_buffer_time(&mut self, buffer_time: Option<Duration>) -> &mut Self {
@@ -113,7 +113,7 @@ impl LazyCacheBuilder {
113113
/// and buffer time jitter fraction is 0.2, then buffer time is adjusted to 8 seconds.
114114
/// Therefore, any requests made after 14 minutes and 52 seconds will load a new identity.
115115
///
116-
/// Defaults to a randomly generated value between 0.0 and 1.0. This setter is for testing only.
116+
/// Defaults to a randomly generated value between 0.0 and 0.5. This setter is for testing only.
117117
#[allow(unused)]
118118
#[cfg(test)]
119119
fn buffer_time_jitter_fraction(mut self, buffer_time_jitter_fraction: fn() -> f64) -> Self {
@@ -127,7 +127,7 @@ impl LazyCacheBuilder {
127127
/// and buffer time jitter fraction is 0.2, then buffer time is adjusted to 8 seconds.
128128
/// Therefore, any requests made after 14 minutes and 52 seconds will load a new identity.
129129
///
130-
/// Defaults to a randomly generated value between 0.0 and 1.0. This setter is for testing only.
130+
/// Defaults to a randomly generated value between 0.0 and 0.5. This setter is for testing only.
131131
#[allow(unused)]
132132
#[cfg(test)]
133133
fn set_buffer_time_jitter_fraction(

0 commit comments

Comments
 (0)