Skip to content

Commit 2106a06

Browse files
committed
fixup: improve based on gemini feedback
Signed-off-by: Simon Schrottner <[email protected]>
1 parent af1e05f commit 2106a06

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

providers/flagd/flagd-testbed

providers/flagd/pkg/provider_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,12 @@ func TestNewProvider(t *testing.T) {
305305
options: []ProviderOption{
306306
WithInProcessResolver(),
307307
WithContextEnricher(func(m map[string]any) *of.EvaluationContext {
308-
m["test2"] = "test2"
309-
context := of.NewTargetlessEvaluationContext(m)
308+
newMap := make(map[string]any, len(m)+1)
309+
for k, v := range m {
310+
newMap[k] = v
311+
}
312+
newMap["test2"] = "test2"
313+
context := of.NewTargetlessEvaluationContext(newMap)
310314
return &context
311315
}),
312316
},
@@ -413,10 +417,8 @@ func TestNewProvider(t *testing.T) {
413417

414418
if test.expectContextEnrichment != nil {
415419
enriched := config.ContextEnricher(enrichment).Attributes()
416-
for k, v := range test.expectContextEnrichment {
417-
if enriched[k] != v {
418-
t.Errorf("incorrect context_enrichment attribute, expected %v, got %v", v, enriched[k])
419-
}
420+
if !reflect.DeepEqual(test.expectContextEnrichment, enriched) {
421+
t.Errorf("incorrect context_enrichment attribute, expected %v, got %v", test.expectContextEnrichment, enriched)
420422
}
421423
}
422424

providers/flagd/pkg/service/in_process/service.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type InProcess struct {
3333
syncEnd context.CancelFunc
3434
wg parallel.WaitGroup
3535
contextValues map[string]any
36+
mtx parallel.RWMutex
3637
}
3738

3839
type Configuration struct {
@@ -298,7 +299,19 @@ func (i *InProcess) appendMetadata(evalMetadata model.Metadata) {
298299
}
299300

300301
func (i *InProcess) ContextValues() map[string]any {
301-
return i.contextValues
302+
i.mtx.RLock()
303+
defer i.mtx.RUnlock()
304+
305+
if i.contextValues == nil {
306+
return nil
307+
}
308+
309+
// Return a copy to prevent mutation of internal state
310+
contextValuesCopy := make(map[string]any, len(i.contextValues))
311+
for k, v := range i.contextValues {
312+
contextValuesCopy[k] = v
313+
}
314+
return contextValuesCopy
302315
}
303316

304317
// makeSyncProvider is a helper to create sync.ISync and return the underlying uri used by it to the caller

0 commit comments

Comments
 (0)