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

Merged
merged 2 commits into from
Oct 18, 2024

Conversation

Arthur1
Copy link
Contributor

@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 ✅

Please upload report for BASE (main@3551f3c). Learn more about missing BASE report.
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #286   +/-   ##
=======================================
  Coverage        ?   81.89%           
=======================================
  Files           ?       10           
  Lines           ?     1215           
  Branches        ?        0           
=======================================
  Hits            ?      995           
  Misses          ?      199           
  Partials        ?       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
@toddbaert toddbaert self-requested a review October 18, 2024 11:07
@toddbaert
Copy link
Member

Nice catch! Sorry for the delay!

@toddbaert toddbaert merged commit 01953bb into open-feature:main Oct 18, 2024
8 checks passed
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.

3 participants