Timeouts, Concurrency, and Workflow Controls
What you'll learn: How to prevent runaway workflows, manage simultaneous runs, and implement smart cancellation policies in GitHub Actions.
Why Control Workflow Execution?
Without guardrails, workflows can consume excessive runner resources, run indefinitely when stuck, or pile up when triggered rapidly. GitHub Actions provides three control mechanisms to prevent chaos: timeouts (time limits), concurrency (limiting simultaneous runs), and cancellation policies (when to stop).
Setting Timeouts
Think of timeouts as a safety timer on your oven—they prevent disasters when something goes wrong. You can set time limits at both job and step levels:
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 30 # Job fails if it exceeds 30 minutes
steps:
- name: Run tests
run: npm test
timeout-minutes: 10 # This step gets 10 minutes max
Default timeout is 360 minutes (6 hours), but shorter limits catch problems faster and free runners sooner.
Managing Concurrency
Concurrency controls prevent multiple workflow runs from stepping on each other's toes—like ensuring only one person uses the bathroom at a time. This is crucial for deployments:
concurrency:
group: production-deploy
cancel-in-progress: true # Cancel older runs when new one starts
The group acts as a lock identifier. Workflows with the same group name won't run simultaneously. Setting cancel-in-progress: false queues new runs instead.
Cancellation Policies
When cancel-in-progress is true, you're saying "the newest version matters most." Perfect for deployment pipelines where only the latest code matters. When false, every run completes—better for critical tasks like data processing.
Key Takeaway: Use timeouts to prevent stuck workflows, concurrency groups to control simultaneous runs, and cancellation policies to decide whether newer runs should stop older ones—protecting your runner resources and ensuring predictable pipeline behavior.