13788: Fix concurrent map write.
authorTom Clegg <tclegg@veritasgenetics.com>
Thu, 19 Jul 2018 19:26:02 +0000 (15:26 -0400)
committerTom Clegg <tclegg@veritasgenetics.com>
Thu, 19 Jul 2018 19:26:02 +0000 (15:26 -0400)
Reading multiple pages into the same ContainerList was reusing
embedded maps that had been passed to other goroutines.

Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg@veritasgenetics.com>

sdk/go/dispatch/dispatch.go

index 3289c67b013f37a67ae8ddeaa52d3fd74abe34e5..c3d60309992c9368ba7a2d75586db58829c8f2c0 100644 (file)
@@ -162,19 +162,21 @@ func (d *Dispatcher) checkForUpdates(filters [][]interface{}, todo map[string]*r
        params := arvadosclient.Dict{
                "filters": filters,
                "order":   []string{"priority desc"}}
-
-       var list arvados.ContainerList
-       for offset, more := 0, true; more; offset += len(list.Items) {
+       offset := 0
+       for {
                params["offset"] = offset
+               var list arvados.ContainerList
                err := d.Arv.List("containers", params, &list)
                if err != nil {
                        log.Printf("Error getting list of containers: %q", err)
                        return false
                }
-               more = len(list.Items) > 0 && list.ItemsAvailable > len(list.Items)+offset
                d.checkListForUpdates(list.Items, todo)
+               offset += len(list.Items)
+               if len(list.Items) == 0 || list.ItemsAvailable <= offset {
+                       return true
+               }
        }
-       return true
 }
 
 func (d *Dispatcher) checkListForUpdates(containers []arvados.Container, todo map[string]*runTracker) {