Remove unused eventsWG in WatchConfig

eventsWG.Wait() is called after initWG.Done(), so the inner goroutine is dangling and cannot be waited by the surrounding one.
So remove the useless waitGroup
This commit is contained in:
david-berichon 2020-01-25 13:07:47 +01:00 committed by GitHub
parent f2cbaea4c2
commit 2e6c46a2ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -358,14 +358,13 @@ func (v *Viper) WatchConfig() {
configDir, _ := filepath.Split(configFile)
realConfigFile, _ := filepath.EvalSymlinks(filename)
eventsWG := sync.WaitGroup{}
eventsWG.Add(1)
go func() {
watcher.Add(configDir)
initWG.Done() // done initializing the watch in this go routine, so the parent routine can move on...
for {
select {
case event, ok := <-watcher.Events:
if !ok { // 'Events' channel is closed
eventsWG.Done()
return
}
currentConfigFile, _ := filepath.EvalSymlinks(filename)
@ -386,7 +385,6 @@ func (v *Viper) WatchConfig() {
}
} else if filepath.Clean(event.Name) == configFile &&
event.Op&fsnotify.Remove&fsnotify.Remove != 0 {
eventsWG.Done()
return
}
@ -394,15 +392,10 @@ func (v *Viper) WatchConfig() {
if ok { // 'Errors' channel is not closed
log.Printf("watcher error: %v\n", err)
}
eventsWG.Done()
return
}
}
}()
watcher.Add(configDir)
initWG.Done() // done initializing the watch in this go routine, so the parent routine can move on...
eventsWG.Wait() // now, wait for event loop to end in this go-routine...
}()
initWG.Wait() // make sure that the go routine above fully ended before returning
}