Skip to content

Commit 41f2621

Browse files
committed
fix: multi-provider hook context management
Fixing an issue with the MultiProvider where hook contexts and hints were being lost due to copies of the context data being created in the OpenFeature sdk evaluation. Since key evaluation of Maps using objects is done by reference, the lookup of the context during evaluation was failing, leading to errors. Signed-off-by: Mike Kitzman <[email protected]>
1 parent d21c041 commit 41f2621

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

packages/server/src/provider/multi-provider/multi-provider.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ export class MultiProvider implements Provider {
3030

3131
public readonly events = new OpenFeatureEventEmitter();
3232

33-
private hookContexts: WeakMap<EvaluationContext, HookContext> = new WeakMap<EvaluationContext, HookContext>();
34-
private hookHints: WeakMap<EvaluationContext, HookHints> = new WeakMap<EvaluationContext, HookHints>();
35-
33+
private hookContents: Array<[HookContext, HookHints]> = [];
34+
3635
metadata: ProviderMetadata;
3736

3837
providerEntries: RegisteredProvider[] = [];
@@ -140,9 +139,8 @@ export class MultiProvider implements Provider {
140139
defaultValue: T,
141140
context: EvaluationContext,
142141
): Promise<ResolutionDetails<T>> {
143-
const hookContext = this.hookContexts.get(context);
144-
const hookHints = this.hookHints.get(context);
145-
142+
const [hookContext, hookHints] = this.hookContents.shift() ?? [];
143+
146144
if (!hookContext || !hookHints) {
147145
throw new GeneralError('Hook context not available for evaluation');
148146
}
@@ -299,8 +297,7 @@ export class MultiProvider implements Provider {
299297
return [
300298
{
301299
before: async (hookContext: BeforeHookContext, hints: HookHints): Promise<EvaluationContext> => {
302-
this.hookContexts.set(hookContext.context, hookContext);
303-
this.hookHints.set(hookContext.context, hints ?? {});
300+
this.hookContents.push([hookContext, hints ?? {}]);
304301
return hookContext.context;
305302
},
306303
},

0 commit comments

Comments
 (0)