Preflight Checklist
Viper Version
1.20.1
Go Version
1.24.5
Config Source
Files
Format
JSON
Repl.it link
No response
Code reproducing the issue
Expected Behavior
A method should be available to manually stop WatchConfig().
Actual Behavior
There are no publicly available methods to stop WatchConfig().
Currently, it seems that memory is only released by the GC when both of the following conditions are met:
-
The Goroutine has exited:
- The configuration file is deleted (triggering an
fsnotify.Remove event).
- Or an error occurs in the watcher (the
watcher.Errors channel is closed or returns an error).
- At this point, the goroutine executes
eventsWG.Done() and exits, releasing its reference to v.
-
No other external references exist:
- Apart from this goroutine, no other code holds a reference to
v (e.g., the caller has set v to nil or no longer uses it).
Steps To Reproduce
No response
Additional Information
Many times, it's necessary to dynamically switch between different configuration files for corresponding settings. While a UI is provided to trigger this (requiring SSE pushes via WatchConfig), the process of switching cannot completely clear the resource usage of the old WatchConfig, leading to leakage issues.
Preflight Checklist
Viper Version
1.20.1
Go Version
1.24.5
Config Source
Files
Format
JSON
Repl.it link
No response
Code reproducing the issue
Expected Behavior
A method should be available to manually stop WatchConfig().
Actual Behavior
There are no publicly available methods to stop WatchConfig().
Currently, it seems that memory is only released by the GC when both of the following conditions are met:
The Goroutine has exited:
fsnotify.Removeevent).watcher.Errorschannel is closed or returns an error).eventsWG.Done()and exits, releasing its reference tov.No other external references exist:
v(e.g., the caller has setvtonilor no longer uses it).Steps To Reproduce
No response
Additional Information
Many times, it's necessary to dynamically switch between different configuration files for corresponding settings. While a UI is provided to trigger this (requiring SSE pushes via WatchConfig), the process of switching cannot completely clear the resource usage of the old WatchConfig, leading to leakage issues.