wg := sync.WaitGroup{}
pdh := m[1]
success := make(chan *http.Response)
- errorChan := make(chan error, h.handler.Cluster.RequestLimits.GetMultiClusterRequestConcurrency())
+ errorChan := make(chan error, len(h.handler.Cluster.RemoteClusters))
// use channel as a semaphore to limit the number of concurrent
// requests at a time
}
go func() {
wg.Wait()
+ close(errorChan)
cancelFunc()
}()
- var errors []string
errorCode := http.StatusNotFound
for {
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 err := range 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
}