Skip to content

Commit 22e2612

Browse files
committed
ci: retry spec fetch with backoff
A transient CDN 520 failed the sdk-typescript scheduled release on 2026-07-07; the same single-shot fetch lives here. Retry up to 5 times with exponential backoff so the daily release run survives upstream blips.
1 parent 3e5da8c commit 22e2612

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

tools/roxygen/main.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,42 @@ func generate() {
114114
syncDocs()
115115
}
116116

117+
// fetchSpec retries with exponential backoff: a transient upstream error (e.g. a
118+
// CDN 520) must not fail the daily release run.
117119
func fetchSpec() []byte {
120+
const attempts = 5
121+
for attempt := 1; ; attempt++ {
122+
body, err := fetchSpecOnce()
123+
if err == nil {
124+
return body
125+
}
126+
if attempt == attempts {
127+
fail("fetch spec: %v (after %d attempts)", err, attempts)
128+
}
129+
delay := time.Duration(1<<attempt) * time.Second
130+
fmt.Printf("Fetch attempt %d/%d failed (%v), retrying in %s\n", attempt, attempts, err, delay)
131+
time.Sleep(delay)
132+
}
133+
}
134+
135+
func fetchSpecOnce() ([]byte, error) {
118136
req, err := http.NewRequest(http.MethodGet, specURL, nil)
119137
check(err, "build request")
120138
req.Header.Set("Cache-Control", "no-cache")
121139
client := &http.Client{Timeout: 60 * time.Second}
122140
resp, err := client.Do(req)
123-
check(err, "fetch spec")
141+
if err != nil {
142+
return nil, err
143+
}
124144
defer resp.Body.Close()
125145
if resp.StatusCode != http.StatusOK {
126-
fail("fetch spec: unexpected status %d", resp.StatusCode)
146+
return nil, fmt.Errorf("unexpected status %d", resp.StatusCode)
127147
}
128148
buf := new(bytes.Buffer)
129-
_, err = buf.ReadFrom(resp.Body)
130-
check(err, "read spec body")
131-
return buf.Bytes()
149+
if _, err := buf.ReadFrom(resp.Body); err != nil {
150+
return nil, err
151+
}
152+
return buf.Bytes(), nil
132153
}
133154

134155
// ─── spec normalization ──────────────────────────────────────────────────────

0 commit comments

Comments
 (0)