open-feature / open-feature/go-sdk

SDK re-initializes a provider already bound to another domain, causing multi-Init

Open
#527 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
250
Forks
62
Avg merge
2d 3h
Merged PRs (30d)
25

Description

### Observed behavior

Every `Set*Provider` call runs `Init` on the newly registered provider unconditionally - even when that provider instance is already active on another domain.

OpenFeature spec requirement 1.1.2.2: "Provider instances which are already active (because they have been bound to another domain or otherwise) need not be initialized again."

### Expected Behavior

Binding an already-active provider to another domain skips `Init` and reports readiness from the provider's existing state.

### Steps to reproduce

```go
func TestRequirementMultiBound(t *testing.T) {
inited := atomic.Bool{}
sh := &stateHandlerForTests{
// Semaphore must be invoked
initF: func(e EvaluationContext) error {
if inited.Swap(true) {
return fmt.Errorf("ready initialized")
}
return nil
},
}
provider := struct {
FeatureProvider
StateHandler
}{
FeatureProvider: NoopProvider{},
StateHandler: sh,
}

api := newAPI()
t.Cleanup(func() {
_ = api.Shutdown(context.Background())
})

err := api.SetProviderAndWait(t.Context(), provider)
if err != nil {
t.Errorf("can't set default: %v", err)
}
err = api.SetProviderAndWait(t.Context(), provider, WithDomain("domain"))
if err != nil {
t.Errorf("can't set domain: %v", err)
}
}
```
Result:
```sh
--- FAIL: TestRequirementMultiBound (0.00s)
openfeature_test.go:88: can't set domain: failed to initialize named provider "NoopProvider" for domain "domain": ready initialized
```

Contributor guide

Open the contributing guide

Research direction

Start with SetProviderAndWait and newAPI in openfeature_test.go, then trace how provider binding and initialization are handled for the default and named domains. Run the TestRequirementMultiBound reproduction and add regression coverage showing that an already-active provider is not initialized again and reports its existing readiness state.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.