X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/516685e09227ab64c2d4f7fd04d4b60a75fc5d0f..664cbad59d3fff30efb7e19c73fa57120a7672b0:/lib/controller/fed_collections.go?ds=inline diff --git a/lib/controller/fed_collections.go b/lib/controller/fed_collections.go index b9cd205829..024af83c2b 100644 --- a/lib/controller/fed_collections.go +++ b/lib/controller/fed_collections.go @@ -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 }