Skip to content

Commit a8a27f1

Browse files
committed
dont lock entire evaluation
Signed-off-by: Todd Baert <[email protected]>
1 parent d5e854a commit a8a27f1

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

src/main/java/dev/openfeature/sdk/OpenFeatureClient.java

+28-21
Original file line numberDiff line numberDiff line change
@@ -67,32 +67,39 @@ private <T> FlagEvaluationDetails<T> evaluateFlag(FlagValueType type, String key
6767
FlagEvaluationDetails<T> details = null;
6868
List<Hook> mergedHooks = null;
6969
HookContext<T> hookCtx = null;
70-
71-
try (AutoCloseableLock __ = OpenFeatureAPI.rwLock.readLockAutoCloseable();
72-
AutoCloseableLock ___ = this.rwLock.readLockAutoCloseable()) {
73-
74-
FeatureProvider provider = ObjectUtils.defaultIfNull(openfeatureApi.getProvider(), () -> {
75-
log.debug("No provider configured, using no-op provider.");
76-
return new NoOpProvider();
77-
});
78-
79-
hookCtx = HookContext.from(key, type, this.getMetadata(),
80-
openfeatureApi.getProvider().getMetadata(), ctx, defaultValue);
81-
82-
mergedHooks = ObjectUtils.merge(provider.getProviderHooks(), flagOptions.getHooks(), clientHooks,
83-
openfeatureApi.getApiHooks());
70+
FeatureProvider provider = null;
71+
72+
try {
73+
EvaluationContext apiContext;
74+
EvaluationContext clientContext;
75+
76+
// lock while getting the provider and hooks
77+
try (AutoCloseableLock __ = OpenFeatureAPI.rwLock.readLockAutoCloseable();
78+
AutoCloseableLock ___ = this.rwLock.readLockAutoCloseable()) {
79+
provider = ObjectUtils.defaultIfNull(openfeatureApi.getProvider(), () -> {
80+
log.debug("No provider configured, using no-op provider.");
81+
return new NoOpProvider();
82+
});
83+
84+
mergedHooks = ObjectUtils.merge(provider.getProviderHooks(), flagOptions.getHooks(), clientHooks,
85+
openfeatureApi.getApiHooks());
86+
87+
hookCtx = HookContext.from(key, type, this.getMetadata(),
88+
provider.getMetadata(), ctx, defaultValue);
89+
90+
// merge of: API.context, client.context, invocation.context
91+
apiContext = openfeatureApi.getEvaluationContext() != null
92+
? openfeatureApi.getEvaluationContext()
93+
: new MutableContext();
94+
clientContext = openfeatureApi.getEvaluationContext() != null
95+
? this.getEvaluationContext()
96+
: new MutableContext();
97+
}
8498

8599
EvaluationContext ctxFromHook = hookSupport.beforeHooks(type, hookCtx, mergedHooks, hints);
86100

87101
EvaluationContext invocationCtx = ctx.merge(ctxFromHook);
88102

89-
// merge of: API.context, client.context, invocation.context
90-
EvaluationContext apiContext = openfeatureApi.getEvaluationContext() != null
91-
? openfeatureApi.getEvaluationContext()
92-
: new MutableContext();
93-
EvaluationContext clientContext = openfeatureApi.getEvaluationContext() != null
94-
? this.getEvaluationContext()
95-
: new MutableContext();
96103
EvaluationContext mergedCtx = apiContext.merge(clientContext.merge(invocationCtx));
97104

98105
ProviderEvaluation<T> providerEval = (ProviderEvaluation<T>) createProviderEvaluation(type, key,

0 commit comments

Comments
 (0)