private RefreshResult HandleFetchedFailure()

in aliyun-net-credentials/Provider/RefreshCachedSupplier.cs [207:239]


        private RefreshResult<T> HandleFetchedFailure(Exception exception)
        {
            Logger.Warn(string.Format("Refresh credentials failed, cached value is {0}, exception is {1}", this.cachedValue, exception));
            var currentCachedValue = this.cachedValue;
            if (currentCachedValue == null)
            {
                Logger.Error(exception.Message);
                throw exception;
            }

            var now = DateTime.UtcNow.GetTimeMillis();
            if (now < currentCachedValue.StaleTime)
            {
                return currentCachedValue;
            }

            var numFailures = Interlocked.Increment(ref consecutiveRefreshFailures);
            switch (this.staleValueBehavior)
            {
                case StaleValueBehavior.Strict:
                    throw exception;
                case StaleValueBehavior.Allow:
                    // 采用退避算法,立刻重试
                    var newStaleTime = JitterTime(now, 1000, MaxStaleFailureJitter(numFailures));
                    Logger.Warn(string.Format(
                        "Cached value expiration has been extended to {0} because calling the downstream service failed (consecutive failures: {1}).",
                        newStaleTime, numFailures));
                    return currentCachedValue.ToBuilder().StaleTime(newStaleTime).Build();
                default:
                    throw new ArgumentException(string.Format("Unknown stale-value-behavior: {0}",
                        this.staleValueBehavior));
            }
        }