Skip to content

Commit 17a7772

Browse files
fix: deadlocks in client applications (#150)
Signed-off-by: DouglasHammon-FV <[email protected]>
1 parent 3da02e6 commit 17a7772

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/OpenFeature/OpenFeatureClient.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,63 +107,63 @@ public FeatureClient(string name, string version, ILogger logger = null, Evaluat
107107
/// <inheritdoc />
108108
public async Task<bool> GetBooleanValue(string flagKey, bool defaultValue, EvaluationContext context = null,
109109
FlagEvaluationOptions config = null) =>
110-
(await this.GetBooleanDetails(flagKey, defaultValue, context, config)).Value;
110+
(await this.GetBooleanDetails(flagKey, defaultValue, context, config).ConfigureAwait(false)).Value;
111111

112112
/// <inheritdoc />
113113
public async Task<FlagEvaluationDetails<bool>> GetBooleanDetails(string flagKey, bool defaultValue,
114114
EvaluationContext context = null, FlagEvaluationOptions config = null) =>
115115
await this.EvaluateFlag(this.ExtractProvider<bool>(provider => provider.ResolveBooleanValue),
116116
FlagValueType.Boolean, flagKey,
117-
defaultValue, context, config);
117+
defaultValue, context, config).ConfigureAwait(false);
118118

119119
/// <inheritdoc />
120120
public async Task<string> GetStringValue(string flagKey, string defaultValue, EvaluationContext context = null,
121121
FlagEvaluationOptions config = null) =>
122-
(await this.GetStringDetails(flagKey, defaultValue, context, config)).Value;
122+
(await this.GetStringDetails(flagKey, defaultValue, context, config).ConfigureAwait(false)).Value;
123123

124124
/// <inheritdoc />
125125
public async Task<FlagEvaluationDetails<string>> GetStringDetails(string flagKey, string defaultValue,
126126
EvaluationContext context = null, FlagEvaluationOptions config = null) =>
127127
await this.EvaluateFlag(this.ExtractProvider<string>(provider => provider.ResolveStringValue),
128128
FlagValueType.String, flagKey,
129-
defaultValue, context, config);
129+
defaultValue, context, config).ConfigureAwait(false);
130130

131131
/// <inheritdoc />
132132
public async Task<int> GetIntegerValue(string flagKey, int defaultValue, EvaluationContext context = null,
133133
FlagEvaluationOptions config = null) =>
134-
(await this.GetIntegerDetails(flagKey, defaultValue, context, config)).Value;
134+
(await this.GetIntegerDetails(flagKey, defaultValue, context, config).ConfigureAwait(false)).Value;
135135

136136
/// <inheritdoc />
137137
public async Task<FlagEvaluationDetails<int>> GetIntegerDetails(string flagKey, int defaultValue,
138138
EvaluationContext context = null, FlagEvaluationOptions config = null) =>
139139
await this.EvaluateFlag(this.ExtractProvider<int>(provider => provider.ResolveIntegerValue),
140140
FlagValueType.Number, flagKey,
141-
defaultValue, context, config);
141+
defaultValue, context, config).ConfigureAwait(false);
142142

143143
/// <inheritdoc />
144144
public async Task<double> GetDoubleValue(string flagKey, double defaultValue,
145145
EvaluationContext context = null,
146146
FlagEvaluationOptions config = null) =>
147-
(await this.GetDoubleDetails(flagKey, defaultValue, context, config)).Value;
147+
(await this.GetDoubleDetails(flagKey, defaultValue, context, config).ConfigureAwait(false)).Value;
148148

149149
/// <inheritdoc />
150150
public async Task<FlagEvaluationDetails<double>> GetDoubleDetails(string flagKey, double defaultValue,
151151
EvaluationContext context = null, FlagEvaluationOptions config = null) =>
152152
await this.EvaluateFlag(this.ExtractProvider<double>(provider => provider.ResolveDoubleValue),
153153
FlagValueType.Number, flagKey,
154-
defaultValue, context, config);
154+
defaultValue, context, config).ConfigureAwait(false);
155155

156156
/// <inheritdoc />
157157
public async Task<Value> GetObjectValue(string flagKey, Value defaultValue, EvaluationContext context = null,
158158
FlagEvaluationOptions config = null) =>
159-
(await this.GetObjectDetails(flagKey, defaultValue, context, config)).Value;
159+
(await this.GetObjectDetails(flagKey, defaultValue, context, config).ConfigureAwait(false)).Value;
160160

161161
/// <inheritdoc />
162162
public async Task<FlagEvaluationDetails<Value>> GetObjectDetails(string flagKey, Value defaultValue,
163163
EvaluationContext context = null, FlagEvaluationOptions config = null) =>
164164
await this.EvaluateFlag(this.ExtractProvider<Value>(provider => provider.ResolveStructureValue),
165165
FlagValueType.Object, flagKey,
166-
defaultValue, context, config);
166+
defaultValue, context, config).ConfigureAwait(false);
167167

168168
private async Task<FlagEvaluationDetails<T>> EvaluateFlag<T>(
169169
(Func<string, T, EvaluationContext, Task<ResolutionDetails<T>>>, FeatureProvider) providerInfo,
@@ -211,32 +211,32 @@ private async Task<FlagEvaluationDetails<T>> EvaluateFlag<T>(
211211
FlagEvaluationDetails<T> evaluation;
212212
try
213213
{
214-
var contextFromHooks = await this.TriggerBeforeHooks(allHooks, hookContext, options);
214+
var contextFromHooks = await this.TriggerBeforeHooks(allHooks, hookContext, options).ConfigureAwait(false);
215215

216216
evaluation =
217-
(await resolveValueDelegate.Invoke(flagKey, defaultValue, contextFromHooks.EvaluationContext))
217+
(await resolveValueDelegate.Invoke(flagKey, defaultValue, contextFromHooks.EvaluationContext).ConfigureAwait(false))
218218
.ToFlagEvaluationDetails();
219219

220-
await this.TriggerAfterHooks(allHooksReversed, hookContext, evaluation, options);
220+
await this.TriggerAfterHooks(allHooksReversed, hookContext, evaluation, options).ConfigureAwait(false);
221221
}
222222
catch (FeatureProviderException ex)
223223
{
224224
this._logger.LogError(ex, "Error while evaluating flag {FlagKey}. Error {ErrorType}", flagKey,
225225
ex.ErrorType.GetDescription());
226226
evaluation = new FlagEvaluationDetails<T>(flagKey, defaultValue, ex.ErrorType, Reason.Error,
227227
string.Empty, ex.Message);
228-
await this.TriggerErrorHooks(allHooksReversed, hookContext, ex, options);
228+
await this.TriggerErrorHooks(allHooksReversed, hookContext, ex, options).ConfigureAwait(false);
229229
}
230230
catch (Exception ex)
231231
{
232232
this._logger.LogError(ex, "Error while evaluating flag {FlagKey}", flagKey);
233233
var errorCode = ex is InvalidCastException ? ErrorType.TypeMismatch : ErrorType.General;
234234
evaluation = new FlagEvaluationDetails<T>(flagKey, defaultValue, errorCode, Reason.Error, string.Empty);
235-
await this.TriggerErrorHooks(allHooksReversed, hookContext, ex, options);
235+
await this.TriggerErrorHooks(allHooksReversed, hookContext, ex, options).ConfigureAwait(false);
236236
}
237237
finally
238238
{
239-
await this.TriggerFinallyHooks(allHooksReversed, hookContext, options);
239+
await this.TriggerFinallyHooks(allHooksReversed, hookContext, options).ConfigureAwait(false);
240240
}
241241

242242
return evaluation;
@@ -250,7 +250,7 @@ private async Task<HookContext<T>> TriggerBeforeHooks<T>(IReadOnlyList<Hook> hoo
250250

251251
foreach (var hook in hooks)
252252
{
253-
var resp = await hook.Before(context, options?.HookHints);
253+
var resp = await hook.Before(context, options?.HookHints).ConfigureAwait(false);
254254
if (resp != null)
255255
{
256256
evalContextBuilder.Merge(resp);
@@ -271,7 +271,7 @@ private async Task TriggerAfterHooks<T>(IReadOnlyList<Hook> hooks, HookContext<T
271271
{
272272
foreach (var hook in hooks)
273273
{
274-
await hook.After(context, evaluationDetails, options?.HookHints);
274+
await hook.After(context, evaluationDetails, options?.HookHints).ConfigureAwait(false);
275275
}
276276
}
277277

@@ -282,7 +282,7 @@ private async Task TriggerErrorHooks<T>(IReadOnlyList<Hook> hooks, HookContext<T
282282
{
283283
try
284284
{
285-
await hook.Error(context, exception, options?.HookHints);
285+
await hook.Error(context, exception, options?.HookHints).ConfigureAwait(false);
286286
}
287287
catch (Exception e)
288288
{
@@ -298,7 +298,7 @@ private async Task TriggerFinallyHooks<T>(IReadOnlyList<Hook> hooks, HookContext
298298
{
299299
try
300300
{
301-
await hook.Finally(context, options?.HookHints);
301+
await hook.Finally(context, options?.HookHints).ConfigureAwait(false);
302302
}
303303
catch (Exception e)
304304
{

0 commit comments

Comments
 (0)