From bb34537e3b7fb18eea2d6012f851bded27a055d9 Mon Sep 17 00:00:00 2001 From: Lucas Bedatty Date: Wed, 1 Apr 2026 13:46:46 -0300 Subject: [PATCH] fix(gitops-update): add retry with rebase and exponential backoff on push When multiple services update the same GitOps repo concurrently, the push can be rejected because the remote already has new commits. This adds a retry loop (up to 5 attempts) with git pull --rebase and exponential backoff (2s, 4s, 6s, 8s, 10s) to handle race conditions. Closes #197 --- .github/workflows/gitops-update.yml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/gitops-update.yml b/.github/workflows/gitops-update.yml index cf80378..6226c78 100644 --- a/.github/workflows/gitops-update.yml +++ b/.github/workflows/gitops-update.yml @@ -444,7 +444,25 @@ jobs: fi git commit -am "ci(${{ steps.setup.outputs.commit_prefix }}): update image tags ($ENV_LABEL)" || echo "No changes to commit" - git push origin main + + # Retry push with rebase and exponential backoff to handle concurrent updates + MAX_RETRIES=5 + for i in $(seq 1 $MAX_RETRIES); do + if git push origin main; then + echo "Push succeeded on attempt $i" + break + fi + + if [ "$i" -eq "$MAX_RETRIES" ]; then + echo "ERROR: Failed to push after $MAX_RETRIES attempts" + exit 1 + fi + + BACKOFF=$((i * 2)) + echo "Push failed (attempt $i/$MAX_RETRIES), rebasing and retrying in ${BACKOFF}s..." + sleep "$BACKOFF" + git pull --rebase origin main + done # ArgoCD Sync Job - runs in parallel for each server/env combination argocd_sync: