-
Notifications
You must be signed in to change notification settings - Fork 2k
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
fatal error: concurrent map writes panic #629
Comments
Can you share some example code to reproduce the issue? Are you trying to use Viper from separate goroutines? |
Got same problem, but race appears in a place, which is totally unexpected to face it: UnmarshalKey. My expectation was, that unmarshaling part of config into external struct, should not change any internal structures inside viper package. Here is small test, which fails for me in 50% of cases: package main
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
"github.com/spf13/afero"
"github.com/spf13/viper"
)
type Setting struct {
TestValue *string `json:"testValue,omitempty" mapstructure:"testvalue"`
}
func TestConcurrency(t *testing.T) {
content := []byte(`{"settings": {"A": {"value": "value A"}, "B": {"value": "value B"}}}`)
aferoFS := afero.NewMemMapFs()
require.NoError(t, afero.WriteFile(aferoFS, "conf.json", content, 0755))
v := viper.New()
v.SetConfigType("json")
v.SetFs(aferoFS)
v.SetConfigFile("conf.json")
require.NoError(t, v.ReadInConfig())
for i := 1; i < 100; i++ {
t.Run(fmt.Sprintf("flow #%d", i), func(tt *testing.T) {
tt.Parallel()
settings := make(map[string]*Setting)
require.NotPanics(t, func() {
require.NoError(t, v.UnmarshalKey("settings", &settings))
})
})
}
} In my case problem is with |
Is this fixed by 9e56dac? |
Got panic
v1.3.1
The text was updated successfully, but these errors were encountered: