Просмотр исходного кода

set timeout for rate-card api call (#2841)

Signed-off-by: r2k1 <yokree@gmail.com>
r2k1 1 год назад
Родитель
Сommit
f42586093d
1 измененных файлов с 6 добавлено и 1 удалено
  1. 6 1
      pkg/cloud/azure/provider.go

+ 6 - 1
pkg/cloud/azure/provider.go

@@ -846,7 +846,12 @@ func (az *Azure) DownloadPricingData() error {
 	rateCardFilter := fmt.Sprintf("OfferDurableId eq '%s' and Currency eq '%s' and Locale eq 'en-US' and RegionInfo eq '%s'", config.AzureOfferDurableID, config.CurrencyCode, config.AzureBillingRegion)
 
 	log.Infof("Using ratecard query %s", rateCardFilter)
-	result, err := rcClient.Get(context.TODO(), rateCardFilter)
+	// rate-card client is old, it can hang indefinitely in some cases
+	// this happens on the main thread, so it may block the whole app
+	// there is can be a better way to set timeout for the client
+	ctx, cancel := context.WithTimeout(context.TODO(), 60*time.Second)
+	defer cancel()
+	result, err := rcClient.Get(ctx, rateCardFilter)
 	if err != nil {
 		log.Warnf("Error in pricing download query from API")
 		az.rateCardPricingError = err