From 1346492d727b95f28dd812a28f1a3ee861822193 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Mon, 13 Feb 2017 15:34:59 -0500 Subject: [PATCH] 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. --- yamlgraph/gapi.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/yamlgraph/gapi.go b/yamlgraph/gapi.go index f4b4739b..d1005765 100644 --- a/yamlgraph/gapi.go +++ b/yamlgraph/gapi.go @@ -31,10 +31,11 @@ import ( type GAPI struct { File *string // yaml graph definition to use; nil if undefined - data gapi.Data - initialized bool - closeChan chan struct{} - wg sync.WaitGroup // sync group for tunnel go routines + data gapi.Data + initialized bool + closeChan chan struct{} + wg sync.WaitGroup // sync group for tunnel go routines + configWatcher *recwatch.ConfigWatcher } // 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.closeChan = make(chan struct{}) obj.initialized = true + obj.configWatcher = recwatch.NewConfigWatcher() return nil } @@ -88,8 +90,7 @@ func (obj *GAPI) Next() chan error { ch <- fmt.Errorf("yamlgraph: GAPI is not initialized") return } - configWatcher := recwatch.NewConfigWatcher() - configChan := configWatcher.ConfigWatch(*obj.File) // simple + configChan := obj.configWatcher.ConfigWatch(*obj.File) // simple for { select { case err, ok := <-configChan: // returns nil events on ok! @@ -119,6 +120,7 @@ func (obj *GAPI) Close() error { if !obj.initialized { return fmt.Errorf("yamlgraph: GAPI is not initialized") } + obj.configWatcher.Close() close(obj.closeChan) obj.wg.Wait() obj.initialized = false // closed = true