Merge branch '14323-container-collection-mounts'
[arvados.git] / lib / controller / fed_collections.go
index b9cd20582951505fe7b43c07c490be9507535720..024af83c2b36cdd254ec1248ed3df6e3a71e02e0 100644 (file)
@@ -209,15 +209,12 @@ func (h *collectionFederatedRequestHandler) ServeHTTP(w http.ResponseWriter, req
        wg := sync.WaitGroup{}
        pdh := m[1]
        success := make(chan *http.Response)
-       errorChan := make(chan error)
+       errorChan := make(chan error, len(h.handler.Cluster.RemoteClusters))
 
        // use channel as a semaphore to limit the number of concurrent
        // requests at a time
        sem := make(chan bool, h.handler.Cluster.RequestLimits.GetMultiClusterRequestConcurrency())
 
-       defer close(errorChan)
-       defer close(success)
-       defer close(sem)
        defer cancelFunc()
 
        for remoteID := range h.handler.Cluster.RemoteClusters {
@@ -277,7 +274,6 @@ func (h *collectionFederatedRequestHandler) ServeHTTP(w http.ResponseWriter, req
                cancelFunc()
        }()
 
-       var errors []string
        errorCode := http.StatusNotFound
 
        for {
@@ -285,14 +281,17 @@ func (h *collectionFederatedRequestHandler) ServeHTTP(w http.ResponseWriter, req
                case newResp = <-success:
                        h.handler.proxy.ForwardResponse(w, newResp, nil)
                        return
-               case err := <-errorChan:
-                       if httperr, ok := err.(HTTPError); ok {
-                               if httperr.Code != http.StatusNotFound {
-                                       errorCode = http.StatusBadGateway
+               case <-sharedContext.Done():
+                       var errors []string
+                       for len(errorChan) > 0 {
+                               err := <-errorChan
+                               if httperr, ok := err.(HTTPError); ok {
+                                       if httperr.Code != http.StatusNotFound {
+                                               errorCode = http.StatusBadGateway
+                                       }
                                }
+                               errors = append(errors, err.Error())
                        }
-                       errors = append(errors, err.Error())
-               case <-sharedContext.Done():
                        httpserver.Errors(w, errors, errorCode)
                        return
                }