X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/8c30c649c667f7ccd205cdfcf1864563ac503585..08d0b1ab43499b7f13462d5e3555d239b4634d22:/sdk/go/keepclient/discover.go diff --git a/sdk/go/keepclient/discover.go b/sdk/go/keepclient/discover.go index 4377c19515..62936e7183 100644 --- a/sdk/go/keepclient/discover.go +++ b/sdk/go/keepclient/discover.go @@ -6,6 +6,7 @@ package keepclient import ( "encoding/json" + "errors" "fmt" "log" "os" @@ -20,9 +21,10 @@ import ( // ClearCache clears the Keep service discovery cache. func RefreshServiceDiscovery() { + var wg sync.WaitGroup + defer wg.Wait() svcListCacheMtx.Lock() defer svcListCacheMtx.Unlock() - var wg sync.WaitGroup for _, ent := range svcListCache { wg.Add(1) go func() { @@ -30,7 +32,6 @@ func RefreshServiceDiscovery() { wg.Done() }() } - wg.Wait() } // ClearCacheOnSIGHUP installs a signal handler that calls @@ -150,7 +151,22 @@ func (kc *KeepClient) discoverServices() error { } svcListCacheMtx.Unlock() - return kc.loadKeepServers(<-cacheEnt.latest) + select { + case <-time.After(time.Minute): + return errors.New("timed out while getting initial list of keep services") + case sl := <-cacheEnt.latest: + return kc.loadKeepServers(sl) + } +} + +func (kc *KeepClient) RefreshServiceDiscovery() { + svcListCacheMtx.Lock() + ent, ok := svcListCache[kc.Arvados.ApiServer] + svcListCacheMtx.Unlock() + if !ok || kc.Arvados.KeepServiceURIs != nil || kc.disableDiscovery { + return + } + ent.clear <- struct{}{} } // LoadKeepServicesFromJSON gets list of available keep services from