Unraveling Mysterious GitHub Actions Runner Shutdowns: Boosting Engineering Productivity
The Enigma of Unexpected CI/CD Failures
In the world of continuous integration and continuous delivery (CI/CD), few things are as frustrating as an unexpected, seemingly random workflow failure. When your automated tests or builds suddenly halt without a clear error message, it can significantly impede your engineering productivity. This was precisely the challenge faced by a developer in a recent GitHub Community discussion, where GitHub-hosted runners repeatedly shut down at the same point in a workflow, logging a cryptic 'UserCancelled' message.
The user, luiguiHerrera, reported three consecutive failures of a GitHub Actions workflow. Each attempt stopped abruptly after 116 Python tests passed, interrupting subsequent steps and concluding with a 'failure' status. Crucially, the diagnostic logs for the third attempt contained the line: Runner will be shutdown for UserCancelled, followed by an exit code 143. This occurred well before the configured 40-minute job timeout, with no explicit user cancellation, making it a perplexing issue for software project planning and execution.
Decoding 'UserCancelled': More Than Meets the Eye
A key insight from community member kaluarachchiteshan clarified that 'UserCancelled' from the runner's perspective doesn't always mean a human initiated the cancellation. Instead, it indicates a cancel signal received from the GitHub Actions service, which can be triggered by several underlying issues:
- The job's process tree being killed by the operating system (e.g., an Out-Of-Memory (OOM) killer).
- The hosted VM being reclaimed or the job cancelled by the platform.
- An actual workflow cancellation request via API, UI, or another run.
The exit code 143 (128 + 15) corresponds to SIGTERM. While SIGKILL (137) is more typical for an OOM killer, the runner might send SIGTERM to child processes during its own shutdown, so memory pressure cannot be immediately ruled out.
Systematic Troubleshooting for Enhanced Engineering Productivity
To diagnose such elusive issues and maintain robust CI/CD, a systematic approach is vital. Here are the recommended steps, crucial for any team leveraging engineering productivity software like GitHub Actions:
1. Check for Resource Exhaustion on the Hosted Runner
The most common culprit for unexpected shutdowns is resource exhaustion. Unlike local macOS environments, GitHub-hosted Linux runners have specific memory and disk limits. To monitor resources during the workflow, add a diagnostic step:
- name: Monitor resources
run: |
(while true; do
date -u +%T
free -m | sed -n '2p'
df -h / /tmp | tail -n +2
ps -eo pid,rss,cmd --sort=-rss | head -5
echo ---
sleep 5
done) > resource.log 2>&1 &
- name: Run tests
run: python -m unittest -v 2>&1 | tee test.log
- name: Upload diagnostics
if: always()
uses: actions/upload-artifact@v4
with:
name: diagnostics
path: |
resource.log
test.logAfter a failure, examine resource.log for spikes in memory, disk usage, or process counts just before the shutdown. Also, check system logs like dmesg or journalctl -k for OOM killer messages.
2. Isolate the Triggering Code
Since the failure occurred consistently after a specific test, the next step is to isolate that part of the codebase:
- Run only the next test class (e.g.,
python -m unittest path.to.module.ZodSecurityTests -v) to see if it fails in isolation on Actions. - Use Python's fault handlers (
PYTH> andpython -X dev) to get detailed tracebacks if a child process dies. - Investigate any test code that interacts with system resources (e.g., creating temporary Git fixtures, using
os.kill,signal, or manipulatingGITHUB_*environment variables).
3. Rule Out External Cancellation
Verify if any external factors could be initiating a cancellation:
- Check GitHub's audit logs (if available for your plan) for
workflow_run.cancelevents. - Review other workflows in the repository for
concurrency: cancel-in-progressconfigurations. - Use the GitHub REST API to inspect the run's timeline for cancellation triggers:
gh api repos/luiguiHerrera/Luiguiherrera-web/actions/runs/42536568040/attempts/34. Escalate to GitHub Support
If community-led diagnostics don't yield a solution, escalate the issue to GitHub Support. Provide all collected evidence, including run URLs, job IDs, debug logs, runner version, and resource logs. Specifically ask if the runner VM experienced an infrastructure-initiated cancel, OOM, or disk exhaustion.
By systematically applying these diagnostic techniques, developers can effectively troubleshoot mysterious GitHub Actions runner shutdowns, significantly enhancing their engineering productivity and the reliability of their CI/CD pipelines. These insights are invaluable for robust software project planning and execution.
