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

Potential concurrency bugs in ConfigManager #532

Open
djshow832 opened this issue May 10, 2024 · 0 comments
Open

Potential concurrency bugs in ConfigManager #532

djshow832 opened this issue May 10, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@djshow832
Copy link
Collaborator

djshow832 commented May 10, 2024

Development Task

ConfigManager notifies other modules with the config change by a channel. There are some bugs:

  1. When a module starts, it must receive an initial config and a channel as its parameters, such as someModule.Init(cfgMgr.GetConfig(), cfgMgr.WatchConfig()). However, between calling GetConfig() and WatchConfig(), there may be a config change, and thus someModule may miss this config change.
  2. ConfigManager notifies all the modules by writing to the channels when config changes. If one module blocks (maybe forever or temporarily), it hangs. If the module blocks forever, such as deadlock or panic, the config change will block forever. But if you add a timeout on writing the channel, the module may miss the config change if it just blocks temporarily, such as busy handling other things.
  3. There's no way to unsubscribe from ConfigManager after calling WatchConfig(). If a module wants to quit, ConfigManager will still try to notify it.

For the 1st problem, one workaround is calling WatchConfig() after GetConfig().
For the 2nd problem, one workaround is to set the channel size to a big enough size and also set a timeout on writing the channel.
For the 3rd problem, one workaround is to add another function to unsubscribe.

If we deprecate the WatchConfig() way and always use GetConfig(), all problems will be solved.

@djshow832 djshow832 added the bug Something isn't working label May 10, 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

No branches or pull requests

1 participant