File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
sysdig/internal/client/v2 Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import (
1212 "net/http"
1313 "net/http/httputil"
1414 "strings"
15+ "time"
1516
1617 "github.com/draios/terraform-provider-sysdig/buildinfo"
1718 "github.com/hashicorp/go-retryablehttp"
@@ -185,5 +186,27 @@ func newHTTPClient(cfg *config) *http.Client {
185186 transport := http .DefaultTransport .(* http.Transport ).Clone ()
186187 transport .TLSClientConfig = & tls.Config {InsecureSkipVerify : cfg .insecure }
187188 httpClient .HTTPClient = & http.Client {Transport : transport }
189+
190+ // Configure retry logic for 409 Conflict errors with exponential backoff
191+ httpClient .RetryMax = 5
192+ httpClient .RetryWaitMin = 1 * time .Second
193+ httpClient .RetryWaitMax = 30 * time .Second
194+ httpClient .Backoff = retryablehttp .DefaultBackoff // Exponential backoff strategy
195+
196+ httpClient .CheckRetry = func (ctx context.Context , resp * http.Response , err error ) (bool , error ) {
197+ // Use default retry logic for connection errors and 5xx
198+ shouldRetry , checkErr := retryablehttp .DefaultRetryPolicy (ctx , resp , err )
199+ if shouldRetry || checkErr != nil {
200+ return shouldRetry , checkErr
201+ }
202+
203+ // Additionally retry on 409 Conflict
204+ if resp != nil && resp .StatusCode == http .StatusConflict {
205+ return true , nil
206+ }
207+
208+ return false , nil
209+ }
210+
188211 return httpClient .StandardClient ()
189212}
You can’t perform that action at this time.
0 commit comments