Browse code

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>

Kir Kolyshkin authored on 2018/01/17 07:51:36
Showing 1 changed files
... ...
@@ -118,7 +118,8 @@ func (d *Daemon) cleanupMetricsPlugins() {
118 118
 	var wg sync.WaitGroup
119 119
 	wg.Add(len(ls))
120 120
 
121
-	for _, p := range ls {
121
+	for _, plugin := range ls {
122
+		p := plugin
122 123
 		go func() {
123 124
 			defer wg.Done()
124 125
 			pluginStopMetricsCollection(p)