Skip to content

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

Description

@erka

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

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:

--- FAIL: TestRequirementMultiBound (0.00s)
    openfeature_test.go:88: can't set domain: failed to initialize named provider "NoopProvider" for domain "domain": ready initialized

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions