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 <kolyshkin@gmail.com>
Upstream-commit: 9db2c62488734a44a4f1bb9a0252c520b787acfe
Component: engine
This commit is contained in:
Kir Kolyshkin
2018-01-16 15:15:11 -08:00
parent a9d5589889
commit d8a82d08f1
+2 -1
View File
@@ -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)