Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/2.42.18.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
"category": "AWS SDK for Java v2",
"contributor": "",
"description": "Updated endpoint and partition metadata."
},
{
"type": "bugfix",
"category": "AWS SDK for Java v2",
"contributor": "",
"description": "Fix bug in CachedSupplier that disabled InstanceProfileCredentialsProvider credential refreshing after 58 consecutive failures."
}
]
}
6 changes: 6 additions & 0 deletions .changes/next-release/bugfix-AWSSDKforJavav2-a3a0e71.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "AWS SDK for Java v2",
"contributor": "",
"description": "Fix bug in CachedSupplier that retries aggressively after many consecutive failures"
}
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,22 @@ private Duration maxPrefetchJitter(RefreshResult<T> result) {
}

private Duration maxStaleFailureJitter(int numFailures) {
// prevent cycling back through low values
if (numFailures > 63) {
return Duration.ofSeconds(10);
}
long exponentialBackoffMillis = (1L << numFailures - 1) * 100;
if (exponentialBackoffMillis <= 0) {
exponentialBackoffMillis = Long.MAX_VALUE;
}
return ComparableUtils.minimum(Duration.ofMillis(exponentialBackoffMillis), Duration.ofSeconds(10));
}

@SdkTestInternalApi
protected Duration maxStaleFailureJitterTest(int numFailures) {
return maxStaleFailureJitter(numFailures);
}

private Instant jitterTime(Instant time, Duration jitterStart, Duration jitterEnd) {
long jitterRange = jitterEnd.minus(jitterStart).toMillis();
long jitterAmount = Math.abs(jitterRandom.nextLong() % jitterRange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import java.io.Closeable;
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZoneOffset;
Expand Down Expand Up @@ -362,6 +363,28 @@
}
}

@Test
public void maxStaleFailureJitter_shouldNotReturnNegativeOrCycleLowValues() {

Check warning on line 367 in utils/src/test/java/software/amazon/awssdk/utils/cache/CachedSupplierTest.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this 'public' modifier.

See more on https://sonarcloud.io/project/issues?id=aws_aws-sdk-java-v2&issues=AZ0cY32uQTJUEt4E7U9X&open=AZ0cY32uQTJUEt4E7U9X&pullRequest=6811
CachedSupplier<String> supplier = CachedSupplier.builder(() -> RefreshResult.builder("v")
.staleTime(Instant.MAX)
.build())
.build();

for (int i = 1; i <= 70; i++) {
Duration jitter = supplier.maxStaleFailureJitterTest(i);
assertThat(jitter)
.as("numFailures=%d: jitter must be positive", i)
.isPositive();

if (i > 60) {
Comment thread
RanVaknin marked this conversation as resolved.
Outdated
assertThat(jitter)
.isGreaterThan(Duration.ofSeconds(1));
}
}

supplier.close();
}

@Test
public void basicCachingWorks() {
try (WaitingSupplier waitingSupplier = new WaitingSupplier(future(), future())) {
Expand Down
Loading