-
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
Data race in WatchConfig() / ReadInConfig() #174
Comments
The example on main page also has a data race https://github.com/spf13/viper#watching-changes-in-etcd---unencrypted |
same problem, any progress? |
@spf13 ping |
Hit this problem as well @spf13 |
Maybe the config file is getting overwritten too fast by the goroutine and the file system is not protecting files against concurrency. Read THIS. Performing in the same program such kind of low-level direct files operation is like running them from 2 differents programs. Workaround: slowing the file overwriting process not to flood the underlying file system synchronization
output:
|
Write frequency is not the issue. WatchConfig() is fundamentally broken. The issue is that ReadInConfig() is not concurrency-safe, but WatchConfig() calls it from a separate go routine. The only work-around is to not use Get* outside of the OnConfigChange() function. |
viper.ReadInConfig()
is not thread-safe, and when a config file has changed,WatchConfig()
calls it and the user-defined callback without doing any form of synchronization.This results in a data race, as evidenced by this test program:
The text was updated successfully, but these errors were encountered: