yamlgraph: Close the recwatcher properly after use

Don't leave it running unnecessarily! This might have contributed to a
block, but it was hard to isolate if this was the cause or if this was
one of many causes.
This commit is contained in:
James Shubin
2017-02-13 15:34:59 -05:00
parent e5bb8d7992
commit 1346492d72

View File

@@ -35,6 +35,7 @@ type GAPI struct {
initialized bool initialized bool
closeChan chan struct{} closeChan chan struct{}
wg sync.WaitGroup // sync group for tunnel go routines wg sync.WaitGroup // sync group for tunnel go routines
configWatcher *recwatch.ConfigWatcher
} }
// NewGAPI creates a new yamlgraph GAPI struct and calls Init(). // NewGAPI creates a new yamlgraph GAPI struct and calls Init().
@@ -56,6 +57,7 @@ func (obj *GAPI) Init(data gapi.Data) error {
obj.data = data // store for later obj.data = data // store for later
obj.closeChan = make(chan struct{}) obj.closeChan = make(chan struct{})
obj.initialized = true obj.initialized = true
obj.configWatcher = recwatch.NewConfigWatcher()
return nil return nil
} }
@@ -88,8 +90,7 @@ func (obj *GAPI) Next() chan error {
ch <- fmt.Errorf("yamlgraph: GAPI is not initialized") ch <- fmt.Errorf("yamlgraph: GAPI is not initialized")
return return
} }
configWatcher := recwatch.NewConfigWatcher() configChan := obj.configWatcher.ConfigWatch(*obj.File) // simple
configChan := configWatcher.ConfigWatch(*obj.File) // simple
for { for {
select { select {
case err, ok := <-configChan: // returns nil events on ok! case err, ok := <-configChan: // returns nil events on ok!
@@ -119,6 +120,7 @@ func (obj *GAPI) Close() error {
if !obj.initialized { if !obj.initialized {
return fmt.Errorf("yamlgraph: GAPI is not initialized") return fmt.Errorf("yamlgraph: GAPI is not initialized")
} }
obj.configWatcher.Close()
close(obj.closeChan) close(obj.closeChan)
obj.wg.Wait() obj.wg.Wait()
obj.initialized = false // closed = true obj.initialized = false // closed = true