From 66b452503a28461263f6933f9b31cf3bb85f9357 Mon Sep 17 00:00:00 2001 From: "Sk.Lv" Date: Mon, 13 May 2024 16:38:18 +0800 Subject: [PATCH] fix: add request retry when creating security group --- .gitignore | 3 ++- ksyun/service_ksyun_vpc.go | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index c6868c03..26cee31e 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ vendor_bk website_bk go.sum package.json -.DS_Store \ No newline at end of file +.DS_Store +_output/ diff --git a/ksyun/service_ksyun_vpc.go b/ksyun/service_ksyun_vpc.go index c677bdfd..f6702b76 100644 --- a/ksyun/service_ksyun_vpc.go +++ b/ksyun/service_ksyun_vpc.go @@ -1,6 +1,7 @@ package ksyun import ( + "bytes" "context" "fmt" "reflect" @@ -2678,12 +2679,22 @@ func (s *VpcService) CreateSecurityGroupEntryCommonCall(req map[string]interface afterCall: func(d *schema.ResourceData, client *KsyunClient, resp *map[string]interface{}, call ApiCall) (err error) { logger.Debug(logger.RespFormat, call.action, *(call.param), *resp) if isSetId { - var data map[string]interface{} + var ( + data map[string]interface{} + buf bytes.Buffer + retry int + ) + again: data, err = s.ReadSecurityGroupEntry(d, (*(call.param))["SecurityGroupId"].(string)) if err != nil { + if notFoundError(err) && retry < 10 { + time.Sleep(3 * time.Second) + retry++ + goto again + } return err } - buf := securityGroupEntryHashBase(data, true) + buf = securityGroupEntryHashBase(data, true) d.SetId((*(call.param))["SecurityGroupId"].(string) + buf.String()) } return err