Skip to content

Commit 3ab7bc0

Browse files
Implement retry logic for throttling errors in RPC calls (#1219)
1 parent e9afe3e commit 3ab7bc0

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

openapi/rpc.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"fmt"
1818
"os"
1919
"strings"
20+
"time"
2021

2122
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/responses"
2223
"github.com/aliyun/aliyun-cli/cli"
@@ -100,8 +101,18 @@ func (a *RpcInvoker) Prepare(ctx *cli.Context) error {
100101
}
101102

102103
func (a *RpcInvoker) Call() (*responses.CommonResponse, error) {
103-
resp, err := a.client.ProcessCommonRequest(a.request)
104-
// cli.Printf("Resp: %s", resp.String())
104+
var resp *responses.CommonResponse
105+
var err error
106+
107+
for i := 0; i < 5; i++ {
108+
resp, err = a.client.ProcessCommonRequest(a.request)
109+
if err != nil && strings.Contains(err.Error(), "Throttling.User") {
110+
time.Sleep(time.Duration(i+1) * time.Second)
111+
continue
112+
}
113+
break
114+
}
115+
105116
return resp, err
106117
}
107118

0 commit comments

Comments
 (0)