Skip to content

[BUG] Provider lifecycle calls may occur in invalid order #495

@erka

Description

@erka

Observed behavior

In some situations, provider Init may be called after openfeature.Shutdown() call. Additionally, a provider that was not received Init call may got a Shutdown call.

Expected Behavior

No response

Steps to reproduce

func TestProviderInitShutdown(t *testing.T) {
	p := &ttprovider{t: t}
	err := openfeature.SetProvider(p)
	if err != nil {
		t.Fatalf("expected no error, got %v", err)
	}
	openfeature.Shutdown()
	time.Sleep(time.Second)
}

var _ openfeature.StateHandler = (*ttprovider)(nil)

type ttprovider struct {
	openfeature.NoopProvider
	halted atomic.Bool
	t      testing.TB
}

func (a *ttprovider) Init(openfeature.EvaluationContext) error {
	if a.halted.Load() {
		a.t.Fatal("unexpected init call after Shutdown")
	}
	return nil
}

func (a *ttprovider) Shutdown() {
	if a.halted.CompareAndSwap(false, true) {
		a.t.Log("Shutdown was called")
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions