From 43fc99ba83dc6caf37a9669233389e7a0ea3c064 Mon Sep 17 00:00:00 2001 From: yumosx Date: Wed, 25 Feb 2026 17:37:06 +0800 Subject: [PATCH] fix: improve http request retry logic with status code checks Add shouldRetry helper function to determine retryable status codes. Close response body between retry attempts and break early for non-retryable status codes. --- pkg/skills/installer.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/pkg/skills/installer.go b/pkg/skills/installer.go index 6ee7d4c41..a87409528 100644 --- a/pkg/skills/installer.go +++ b/pkg/skills/installer.go @@ -31,14 +31,30 @@ type BuiltinSkill struct { const maxRetries = 3 +func shouldRetry(statusCode int) bool { + return statusCode == http.StatusTooManyRequests || + statusCode >= 500 +} + func doRequestWithRetry(client *http.Client, req *http.Request) (*http.Response, error) { var resp *http.Response var err error + for i := range maxRetries { - resp, err = client.Do(req) - if err == nil && resp.StatusCode == http.StatusOK { - break + if i > 0 && resp != nil { + resp.Body.Close() } + + resp, err = client.Do(req) + if err == nil { + if resp.StatusCode == http.StatusOK { + break + } + if !shouldRetry(resp.StatusCode) { + break + } + } + if i < maxRetries-1 { time.Sleep(time.Second * time.Duration(i+1)) }