Workflow stuck and not cancellable
Asked Answered
G

2

6

I did a misconfiguration with concurrency, initially in the root of my GitHub Actions workflow, and moved to a sub workflow (workflow_call).

Since, I have a workflow that is stuck with label:

enter image description here

I tried to cancel it with gh official CLI, response: gh: Cannot cancel a workflow run that is completed. (HTTP 409)

enter image description here

I also found this other workflow to be stuck, I also tried to cancel it with github api response : {}

enter image description here

Since all my following workflow are stuck.

According to GitHub, it is possible to force cancel a workflow using the API, but this doesn't work.

This is the more detailled force cancel workflow documentation.

How can I force stop a GitHub Actions workflow?

Gervais answered 11/1, 2024 at 10:49 Comment(3)
It would be nice to be able to reproduce your issue with a MRE. Could you share this Update Jira Issue step (with the whole job as well) to see how it was configured? It looks like the workflow is waiting for a manual approval from an environment, is it correct?Antimony
no there is no manual approval, the whole project is available at github.com/pass-culture/pass-culture-main/tree/… , I give this sha because after we reverted a concurrency commit to restore our CIs, as we were totally blocked. the workflow in question is dev_on_push_workflow_main.ymlGervais
For what I understand after looking at your repo, cancelling this run would allow you to cancel the run you shared in your question. For some reason GitHub didn't stop the runner 2 days ago (it probably was during the outage that occurred on that day).Antimony
F
9

EDIT: apologies, I didn't read your original issue properly, you had:

According to GitHub, it is possible to force cancel a workflow using the API, but this doesn't work.

Leaving the rest below for posterity, but clearly this isn't an answer to your q.


If a workflow is stuck, or cannot be canceled for other reasons, there's now a new command (only available through the GH REST API) that forces the cancellation of a workflow: force-cancel.

Using curl

Replace OWNER (or org) and REPO and RUN_ID with your current values.

curl -L \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/repos/OWNER/REPO/actions/runs/RUN_ID/force-cancel

Using GH CLI

Replace OWNER (or org) and REPO and RUN_ID with your current values.

gh api \
  --method POST \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  /repos/OWNER/REPO/actions/runs/RUN_ID/force-cancel

EDIT: while this should just work, I currently have a situation where a run cannot be canceled using the front-end, and using this command, will return a 500 error.

Looks like the GitHub team didn't yet completely fix the issue.

Forgave answered 11/6, 2024 at 16:5 Comment(0)
F
0

I tried the intended solutions, to no avail. Here's what worked:

Try this:

gh api \
  --method POST \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  /repos/{owner}/{repo}/actions/runs/{run_id}/force-cancel

The endpoint /repos/{owner}/{repo}/actions/runs/{run_id}/force-cancel targets a specific run in a specific repository and we attempt to force cancel it. Try this first.

If that doesn't work, try this:

gh api \
  --method DELETE \
  /repos/{owner}/{repo}/actions/runs/{run_id}

This command deletes a workflow run entirely. This will also remove all records of the run.

If that doesn't work or if you don't want to delete the workflow run, try this:

gh api \
  --method PUT \
  -H "Accept: application/vnd.github+json" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  /repos/{owner}/{repo}/contents/{path_to_workflow_file} \
  -f message='Temporarily disable workflow' \
  -f content=$(echo -n 'name: Disabled Workflow
on:
  workflow_dispatch:
jobs:
  disabled:
    runs-on: ubuntu-latest
    steps:
      - run: echo "This workflow is temporarily disabled"' | base64) \
  -f sha=$(gh api /repos/{owner}/{repo}/contents/{path_to_workflow_file} | jq -r .sha)

I don't know why this works, but I suspect it forces GitHub to update or check on the state of the run, and properly cancel it when it is supposed to.

Foment answered 10/8, 2024 at 15:54 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.