Skip to content

Commit 40921b7

Browse files
committed
fix: AppConfig through exception if calling too frequently, use whats in cache
Signed-off-by: Ash.Wani <[email protected]>
1 parent 22ab7bd commit 40921b7

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

Diff for: src/OpenFeature.Contrib.Providers.AwsAppConfig/AppConfigRetrievalApi.cs

+18-6
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,27 @@ public async Task<GetLatestConfigurationResponse>GetLatestConfigurationAsync(Fea
9595
ConfigurationToken = await GetSessionToken(profile)
9696
};
9797

98-
var response = await _appConfigDataClient.GetLatestConfigurationAsync(configurationRequest);
98+
GetLatestConfigurationResponse response;
9999

100-
// If not NextPollConfigurationToken, something wrong with AWS connection.
101-
if(string.IsNullOrWhiteSpace(response.NextPollConfigurationToken)) throw new Exception("Unable to connect to AWS");
100+
try
101+
{
102+
response = await _appConfigDataClient.GetLatestConfigurationAsync(configurationRequest);
103+
}
104+
catch
105+
{
106+
// On exception, could be because of connection issue or
107+
// too frequent call per defined by polling duration, get what's in cache
108+
response = null;
109+
}
102110

103-
// First, update the session token to the newly returned token
104-
_memoryCache.Set(sessionKey, response.NextPollConfigurationToken);
111+
// Update Next Poll configuration token only when one is available.
112+
if(response != null)
113+
{
114+
// First, update the session token to the newly returned token
115+
_memoryCache.Set(sessionKey, response.NextPollConfigurationToken);
116+
}
105117

106-
if((response.Configuration == null || response.Configuration.Length == 0)
118+
if((response?.Configuration == null || response.Configuration.Length == 0)
107119
&& _memoryCache.TryGetValue(configKey, out GetLatestConfigurationResponse configValue))
108120
{
109121
// AppConfig returns empty Configuration if value hasn't changed from last retrieval, hence use what's in cache.

0 commit comments

Comments
 (0)