From 1e3edbc55dc1fab5f7530f078384cfbdf72236d8 Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Wed, 29 Aug 2018 11:38:40 -0700 Subject: [PATCH] Ensure channel closed if an error occurs in cgroup input (#4606) --- plugins/inputs/cgroup/cgroup_linux.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/cgroup/cgroup_linux.go b/plugins/inputs/cgroup/cgroup_linux.go index 0765416af..80c15c963 100644 --- a/plugins/inputs/cgroup/cgroup_linux.go +++ b/plugins/inputs/cgroup/cgroup_linux.go @@ -81,6 +81,7 @@ func isDir(path string) (bool, error) { } func (g *CGroup) generateDirs(list chan<- pathInfo) { + defer close(list) for _, dir := range g.Paths { // getting all dirs that match the pattern 'dir' items, err := filepath.Glob(dir) @@ -101,10 +102,10 @@ func (g *CGroup) generateDirs(list chan<- pathInfo) { } } } - close(list) } func (g *CGroup) generateFiles(dir string, list chan<- pathInfo) { + defer close(list) for _, file := range g.Files { // getting all file paths that match the pattern 'dir + file' // path.Base make sure that file variable does not contains part of path @@ -126,7 +127,6 @@ func (g *CGroup) generateFiles(dir string, list chan<- pathInfo) { } } } - close(list) } // ======================================================================