From 9db2c62488734a44a4f1bb9a0252c520b787acfe Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Tue, 16 Jan 2018 14:51:36 -0800 Subject: [PATCH] daemon.cleanupMetricsPlugins(): fix A linter (vet) found the following bug in the code: > daemon/metrics.go:124::error: range variable p captured by func literal (vet) Here a variable p is used in an async fashion by goroutine, and most probably by the time of use it is set to the last element of a range. For example, the following code ```go for _, c := range []string{"here ", "we ", "go"} { go func() { fmt.Print(c) }() } ``` will print `gogogo` rather than `here we go` as one would expect. Fixes: 0e8e8f0f31 ("Add support for metrics plugins") Signed-off-by: Kir Kolyshkin --- daemon/metrics.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/daemon/metrics.go b/daemon/metrics.go index 44228e7db4..92439ad148 100644 --- a/daemon/metrics.go +++ b/daemon/metrics.go @@ -118,7 +118,8 @@ func (d *Daemon) cleanupMetricsPlugins() { var wg sync.WaitGroup wg.Add(len(ls)) - for _, p := range ls { + for _, plugin := range ls { + p := plugin go func() { defer wg.Done() pluginStopMetricsCollection(p)