From f85e319d649476c8e80f841faf94ee59af97d162 Mon Sep 17 00:00:00 2001 From: Vijay Janapa Reddi Date: Fri, 6 Mar 2026 09:30:42 -0500 Subject: [PATCH] fix: add retry logic to GitHub API requests in update_contributors.py The update_contributors script was failing with intermittent 502 Bad Gateway errors from the GitHub API when fetching commit history. Added retry logic with exponential backoff (up to 3 retries) to handle transient 502, 503, and 504 server errors gracefully. --- .../contributors/update_contributors.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/contributors/update_contributors.py b/.github/workflows/contributors/update_contributors.py index 0a4f96443..39a5d4af3 100644 --- a/.github/workflows/contributors/update_contributors.py +++ b/.github/workflows/contributors/update_contributors.py @@ -1,3 +1,4 @@ +import time #!/usr/bin/env python3 """ Update contributors from GitHub API. @@ -185,10 +186,25 @@ def main(_): last_page = None while next_page != last_page: print(f"Fetching page: {next_page}") - res = requests.get(next_page, headers=headers) + + # Add retry logic for 502/503/504 errors + max_retries = 3 + retry_delay = 5 + for attempt in range(max_retries): + res = requests.get(next_page, headers=headers) + if res.status_code == 200: + break + elif res.status_code in [502, 503, 504]: + logging.warning(f"GitHub API request failed with status {res.status_code} (Attempt {attempt+1}/{max_retries}). Retrying in {retry_delay} seconds...") + time.sleep(retry_delay) + retry_delay *= 2 + else: + break + if res.status_code != 200: logging.error(f"GitHub API request failed with status {res.status_code}: {res.text}") raise RuntimeError(f"Failed to fetch commits: {res.status_code}") + data.extend(res.json()) next_page = res.links.get("next", {}).get("url", None) last_page = res.links.get("last", {}).get("url", None)