From e53c57a30796c22275b43a40b985e76749929085 Mon Sep 17 00:00:00 2001 From: Pengfei Ni Date: Mon, 12 Aug 2019 16:42:14 +0800 Subject: [PATCH] Fix Azure client requests stuck issues on http.StatusTooManyRequests --- .../k8s.io/legacy-cloud-providers/azure/azure.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go b/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go index 0ef4e6d8367..8ac083e2dea 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go +++ b/staging/src/k8s.io/legacy-cloud-providers/azure/azure.go @@ -20,6 +20,7 @@ import ( "fmt" "io" "io/ioutil" + "net/http" "strings" "sync" "time" @@ -238,6 +239,20 @@ type Cloud struct { } func init() { + // In go-autorest SDK https://github.com/Azure/go-autorest/blob/master/autorest/sender.go#L258-L287, + // if ARM returns http.StatusTooManyRequests, the sender doesn't increase the retry attempt count, + // hence the Azure clients will keep retrying forever until it get a status code other than 429. + // So we explicitly removes http.StatusTooManyRequests from autorest.StatusCodesForRetry. + // Refer https://github.com/Azure/go-autorest/issues/398. + // TODO(feiskyer): Use autorest.SendDecorator to customize the retry policy when new Azure SDK is available. + statusCodesForRetry := make([]int, 0) + for _, code := range autorest.StatusCodesForRetry { + if code != http.StatusTooManyRequests { + statusCodesForRetry = append(statusCodesForRetry, code) + } + } + autorest.StatusCodesForRetry = statusCodesForRetry + cloudprovider.RegisterCloudProvider(CloudProviderName, NewCloud) }