From f450c82449b6c2ae61b9db2232c9cb8aef294956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Sat, 22 Dec 2018 10:59:06 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=BF=E9=87=8C=E4=BA=91API=20=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E9=87=8D=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/util/aliyun/aliyun.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/util/aliyun/aliyun.go b/pkg/util/aliyun/aliyun.go index a349daf940..77233a0c8f 100644 --- a/pkg/util/aliyun/aliyun.go +++ b/pkg/util/aliyun/aliyun.go @@ -47,14 +47,19 @@ func NewAliyunClient(providerId string, providerName string, accessKey string, s func jsonRequest(client *sdk.Client, apiName string, params map[string]string) (jsonutils.JSONObject, error) { for i := 1; i < 4; i++ { resp, err := _jsonRequest(client, "ecs.aliyuncs.com", ALIYUN_API_VERSION, apiName, params) + retry := false if err != nil { for _, code := range []string{"SignatureNonceUsed", "InvalidInstance.NotSupported"} { if strings.Contains(err.Error(), code) { - time.Sleep(time.Second * time.Duration(i*10)) - continue + retry = true + break } } } + if retry { + time.Sleep(time.Second * time.Duration(i*10)) + continue + } return resp, err } return nil, fmt.Errorf("timeout for request %s params: %s", apiName, params)