Skip to content

Commit

Permalink
Shorten the defeult timeout of individual call to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardChen820 committed Feb 13, 2025
1 parent 40768ff commit 71a346e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.
//
using Azure.Core;
using Azure.Core.Pipeline;
using Azure.Data.AppConfiguration;
using Microsoft.Extensions.Azure;
using Microsoft.Extensions.Configuration.AzureAppConfiguration.AzureKeyVault;
Expand All @@ -11,6 +12,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;

namespace Microsoft.Extensions.Configuration.AzureAppConfiguration
Expand All @@ -23,6 +25,7 @@ public class AzureAppConfigurationOptions
{
private const int MaxRetries = 2;
private static readonly TimeSpan MaxRetryDelay = TimeSpan.FromMinutes(1);
private static readonly TimeSpan NetworkTimeout = TimeSpan.FromSeconds(10);

private List<KeyValueWatcher> _changeWatchers = new List<KeyValueWatcher>();
private List<KeyValueWatcher> _multiKeyWatchers = new List<KeyValueWatcher>();
Expand Down Expand Up @@ -473,6 +476,10 @@ private static ConfigurationClientOptions GetDefaultClientOptions()
clientOptions.Retry.MaxDelay = MaxRetryDelay;
clientOptions.Retry.Mode = RetryMode.Exponential;
clientOptions.AddPolicy(new UserAgentHeaderPolicy(), HttpPipelinePosition.PerCall);
clientOptions.Transport = new HttpClientTransport(new HttpClient()
{
Timeout = NetworkTimeout
});

return clientOptions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,13 @@ await ExecuteWithFailOverPolicyAsync<object>(clients, async (client) =>

private bool IsFailOverable(AggregateException ex)
{
TaskCanceledException tce = ex.InnerExceptions?.LastOrDefault(e => e is TaskCanceledException) as TaskCanceledException;

if (tce != null && tce.InnerException is TimeoutException)
{
return true;
}

RequestFailedException rfe = ex.InnerExceptions?.LastOrDefault(e => e is RequestFailedException) as RequestFailedException;

return rfe != null ? IsFailOverable(rfe) : false;
Expand Down

0 comments on commit 71a346e

Please sign in to comment.