Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent panic when setting non-comparable named providers #286

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Arthur1
Copy link

@Arthur1 Arthur1 commented Sep 24, 2024

This PR

If we set non-comparable provider multiple times as a named provider, runtime error panic occurs.

reflect.DeepEqual() is generally used for provider-to-provider comparisons, but in one place a simple != is used for comparison between providers.

if reference.featureProvider != handler {

This PR prevents panic by replacing the != comparison with DeepEqual.

Related Issues

How to test

reproduce the problem

go.mod:

module hoge

go 1.23.0

require github.com/open-feature/go-sdk v1.13.0

require (
	github.com/go-logr/logr v1.4.2 // indirect
	golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
)

main.go:

package main

import (
	"fmt"

	"github.com/open-feature/go-sdk/openfeature"
	"github.com/open-feature/go-sdk/openfeature/memprovider"
)

func main() {
	openfeature.SetNamedProviderAndWait("a", memprovider.NewInMemoryProvider(nil))
	openfeature.SetNamedProviderAndWait("b", memprovider.NewInMemoryProvider(nil))
	fmt.Println("succeeded.")
}

run:

$ go run ./main.go                                                                  ✘ 1
panic: runtime error: comparing uncomparable type memprovider.InMemoryProvider

goroutine 1 [running]:
github.com/open-feature/go-sdk/openfeature.(*eventExecutor).triggerEvent(0x14000130000, {{0x1028f7cb9, 0x10}, {0x1028f774f, 0xe}, {{0x1028fbf11, 0x22}, {0x0, 0x0, 0x0}, ...}}, ...)
	/Users/arthur-1/go/pkg/mod/github.com/open-feature/go-sdk@v1.13.0/openfeature/event_executor.go:347 +0x1ec
github.com/open-feature/go-sdk/openfeature.(*evaluationAPI).initNewAndShutdownOld(0x14000130080, {0x10294dd50, 0x0}, {0x0, 0x0}, 0x54?)
	/Users/arthur-1/go/pkg/mod/github.com/open-feature/go-sdk@v1.13.0/openfeature/openfeature_api.go:236 +0x1dc
github.com/open-feature/go-sdk/openfeature.(*evaluationAPI).SetNamedProvider(0x14000130080, {0x10291d700, 0x1}, {0x10294dd50, 0x0}, 0x0)
	/Users/arthur-1/go/pkg/mod/github.com/open-feature/go-sdk@v1.13.0/openfeature/openfeature_api.go:76 +0x110
github.com/open-feature/go-sdk/openfeature.SetNamedProviderAndWait(...)
	/Users/arthur-1/go/pkg/mod/github.com/open-feature/go-sdk@v1.13.0/openfeature/openfeature.go:59
main.main()
	/Users/arthur-1/Repositories/private/openfeature-sdk-panic/main.go:12 +0x88
exit status 2

Verify the fix

go.mod:

 module hoge
 
 go 1.23.0
 
 require github.com/open-feature/go-sdk v1.13.0
 
 require (
 	github.com/go-logr/logr v1.4.2 // indirect
 	golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
 )

+replace github.com/open-feature/go-sdk v1.13.0 => github.com/Arthur1/openfeature-go-sdk v0.0.0-20240924220603-27a4a711ba16

run:

$ go run ./main.go
succeeded.

@Arthur1 Arthur1 requested a review from a team as a code owner September 24, 2024 22:02
Signed-off-by: ASAKURA Kazuki <32762324+Arthur1@users.noreply.github.com>
Copy link

codecov bot commented Sep 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.12%. Comparing base (fb88c24) to head (27a4a71).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #286   +/-   ##
=======================================
  Coverage   82.12%   82.12%           
=======================================
  Files          10       10           
  Lines         990      990           
=======================================
  Hits          813      813           
  Misses        156      156           
  Partials       21       21           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@beeme1mr beeme1mr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@beeme1mr beeme1mr added the bug Something isn't working label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants