From f08caca8a025a3260b46aaed25677c0a9bd393f0 Mon Sep 17 00:00:00 2001 From: Clinton Kitson Date: Fri, 26 Feb 2016 08:57:44 -0800 Subject: [PATCH] Fixes plugin file descriptor leak on plugin discovery Signed-off-by: Clinton Kitson --- plugins/plugins.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/plugins/plugins.go b/plugins/plugins.go index 7157107..738686e 100644 --- a/plugins/plugins.go +++ b/plugins/plugins.go @@ -199,17 +199,27 @@ func GetAll(imp string) ([]*Plugin, error) { err error } - chPl := make(chan plLoad, len(pluginNames)) + chPl := make(chan *plLoad, len(pluginNames)) + var wg sync.WaitGroup for _, name := range pluginNames { + if pl, ok := storage.plugins[name]; ok { + chPl <- &plLoad{pl, nil} + continue + } + + wg.Add(1) go func(name string) { + defer wg.Done() pl, err := loadWithRetry(name, false) - chPl <- plLoad{pl, err} + chPl <- &plLoad{pl, err} }(name) } + wg.Wait() + close(chPl) + var out []*Plugin - for i := 0; i < len(pluginNames); i++ { - pl := <-chPl + for pl := range chPl { if pl.err != nil { logrus.Error(err) continue