in src/main/java/com/aliyun/credentials/provider/RefreshCachedSupplier.java [152:178]
RefreshResult<T> handleFetchedFailure(Exception exception) throws Exception {
logger.warning("Refresh credentials failed, cached value is {}, error: {}", cachedValue, exception.getMessage());
RefreshResult<T> currentCachedValue = cachedValue;
if (currentCachedValue == null) {
throw logger.logThrowableAsError(exception);
}
long now = new Date().getTime();
if (now < currentCachedValue.staleTime()) {
return currentCachedValue;
}
int numFailures = consecutiveRefreshFailures.incrementAndGet();
switch (staleValueBehavior) {
case STRICT:
throw logger.logThrowableAsError(exception);
case ALLOW:
// 采用退避算法,立刻重试
long newStaleTime = jitterTime(now, 1000, maxStaleFailureJitter(numFailures));
logger.warning("Cached value expiration has been extended to " + newStaleTime + " because calling the "
+ "downstream service failed (consecutive failures: " + numFailures + ").");
return currentCachedValue.toBuilder()
.staleTime(newStaleTime)
.build();
default:
throw new IllegalStateException("Unknown stale-value-behavior: " + staleValueBehavior);
}
}