9996: Stop retrieving collections if a fatal error makes any further work futile.
authorTom Clegg <tom@curoverse.com>
Thu, 8 Sep 2016 21:02:22 +0000 (17:02 -0400)
committerTom Clegg <tom@curoverse.com>
Thu, 8 Sep 2016 21:02:22 +0000 (17:02 -0400)
services/keep-balance/balance.go

index 25b474b9ca0a475f81cc08db02ef007e9fe009f0..8fc06c3534b76054cecbfdb1116007579952bcb1 100644 (file)
@@ -244,6 +244,12 @@ func (bal *Balancer) GetCurrentState(c *arvados.Client, pageSize, bufs int) erro
                                errs <- fmt.Errorf("%s: %v", srv, err)
                                return
                        }
+                       if len(errs) > 0 {
+                               // Some other goroutine encountered an
+                               // error -- any futher effort here
+                               // will be wasted.
+                               return
+                       }
                        bal.logf("%s: add %d replicas to map", srv, len(idx))
                        bal.BlockStateMap.AddReplicas(srv, idx)
                        bal.logf("%s: done", srv)
@@ -298,14 +304,11 @@ func (bal *Balancer) GetCurrentState(c *arvados.Client, pageSize, bufs int) erro
                }
        }()
 
-       go func() {
-               // Send a nil error when all goroutines finish. If
-               // this is the first error sent to errs, then
-               // everything worked.
-               wg.Wait()
-               errs <- nil
-       }()
-       return <-errs
+       wg.Wait()
+       if len(errs) > 0 {
+               return <-errs
+       }
+       return nil
 }
 
 func (bal *Balancer) addCollection(coll arvados.Collection) error {