14287: Clarify use of separate variables in goroutine.
authorTom Clegg <tclegg@veritasgenetics.com>
Mon, 22 Jul 2019 17:04:07 +0000 (13:04 -0400)
committerTom Clegg <tclegg@veritasgenetics.com>
Mon, 22 Jul 2019 17:05:51 +0000 (13:05 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg@veritasgenetics.com>

lib/controller/federation/list.go

index 5a171c9c37992f128d14cf81028a00d113268db2..4843baa5c4fc6be3baef6cfe15edeee5d7063e16 100644 (file)
@@ -181,14 +181,14 @@ func (conn *Conn) splitListRequest(ctx context.Context, opts arvados.ListOptions
        defer cancel()
        errs := make(chan error, len(todoByRemote))
        for clusterID, todo := range todoByRemote {
-               clusterID, todo := clusterID, todo
-               batch := make([]string, 0, len(todo))
-               for uuid := range todo {
-                       batch = append(batch, uuid)
-               }
-               go func() {
+               go func(clusterID string, todo map[string]bool) {
                        // This goroutine sends exactly one value to
                        // errs.
+                       batch := make([]string, 0, len(todo))
+                       for uuid := range todo {
+                               batch = append(batch, uuid)
+                       }
+
                        var backend arvados.API
                        if clusterID == conn.cluster.ClusterID {
                                backend = conn.local
@@ -225,13 +225,13 @@ func (conn *Conn) splitListRequest(ctx context.Context, opts arvados.ListOptions
                                }
                        }
                        errs <- nil
-               }()
+               }(clusterID, todo)
        }
 
        // Wait for all goroutines to return, then return the first
        // non-nil error, if any.
        var firstErr error
-       for i := 0; i < len(todoByRemote); i++ {
+       for range todoByRemote {
                if err := <-errs; err != nil && firstErr == nil {
                        firstErr = err
                        // Signal to any remaining fn() calls that