From 70a883b1915224630bbec4635cd2478e131d06d5 Mon Sep 17 00:00:00 2001 From: Bandhan Majumder <133476557+bandhan-majumder@users.noreply.github.com> Date: Tue, 16 Jun 2026 17:46:01 +0530 Subject: [PATCH] fix(ci): retry workflow cancellation on 409 conflicts (#29584) --- .github/workflows/run-ci.yml | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/.github/workflows/run-ci.yml b/.github/workflows/run-ci.yml index 00ba78b46b..30f1e3d2c3 100644 --- a/.github/workflows/run-ci.yml +++ b/.github/workflows/run-ci.yml @@ -72,11 +72,26 @@ jobs: if (latestRun.status === 'in_progress' || latestRun.status === 'queued') { console.log(`Workflow is running (status: ${latestRun.status}). Cancelling it first...`); - await github.rest.actions.cancelWorkflowRun({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: latestRun.id, - }); + const cancelMaxRetries = 10; + const cancelRetryDelay = 3000; + for (let attempt = 1; attempt <= cancelMaxRetries; attempt++) { + try { + await github.rest.actions.cancelWorkflowRun({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: latestRun.id, + }); + console.log(`Cancel request accepted on attempt ${attempt}`); + break; + } catch (err) { + if (err.status === 409 && attempt < cancelMaxRetries) { + console.log(`Cancel attempt ${attempt} got 409 (not yet cancellable), retrying in ${cancelRetryDelay / 1000}s...`); + await new Promise(resolve => setTimeout(resolve, cancelRetryDelay)); + } else { + throw err; + } + } + } // Wait for the workflow to be cancelled (poll with timeout) const maxWaitTime = 60000; // 60 seconds