From b8c39af11bb345785d7cc9e64f0856a07ce70757 Mon Sep 17 00:00:00 2001 From: Nico Vergauwen Date: Fri, 11 Jun 2021 15:25:01 +0200 Subject: [PATCH] discovery: getOrch timeout per orchestrators instead of for all --- discovery/discovery.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/discovery/discovery.go b/discovery/discovery.go index 9e30ad45af..8a861e6798 100644 --- a/discovery/discovery.go +++ b/discovery/discovery.go @@ -17,7 +17,8 @@ import ( "github.com/golang/glog" ) -var getOrchestratorsTimeoutLoop = 1 * time.Second +var getOrchestratorsTimeoutLoop = 500 * time.Millisecond +var getOrchestratorCutoffTime = 4 * time.Second var serverGetOrchInfo = server.GetOrchestratorInfo @@ -49,7 +50,6 @@ func (o *orchestratorPool) GetURLs() []*url.URL { func (o *orchestratorPool) GetOrchestrators(numOrchestrators int, suspender common.Suspender, caps common.CapabilityComparator) ([]*net.OrchestratorInfo, error) { numAvailableOrchs := len(o.uris) numOrchestrators = int(math.Min(float64(numAvailableOrchs), float64(numOrchestrators))) - ctx, cancel := context.WithTimeout(context.Background(), getOrchestratorsTimeoutLoop) infoCh := make(chan *net.OrchestratorInfo, numAvailableOrchs) errCh := make(chan error, numAvailableOrchs) @@ -81,6 +81,8 @@ func (o *orchestratorPool) GetOrchestrators(numOrchestrators int, suspender comm return caps.CompatibleWith(info.Capabilities) } getOrchInfo := func(uri *url.URL) { + ctx, cancel := context.WithTimeout(context.Background(), getOrchestratorsTimeoutLoop) + defer cancel() info, err := serverGetOrchInfo(ctx, o.bcast, uri) if err == nil && isCompatible(info) { infoCh <- info @@ -101,6 +103,8 @@ func (o *orchestratorPool) GetOrchestrators(numOrchestrators int, suspender comm uris[i] = o.uris[j] } + ctx, cancel := context.WithTimeout(context.Background(), getOrchestratorCutoffTime) + for _, uri := range uris { go getOrchInfo(uri) }