Skip to content
Latchkey

PowerShell long-running job timeout in CI

A PowerShell background job or a long external command ran past its time budget and the runner cancelled the step. Sometimes the work is genuinely slow; sometimes it stalled on a transient hang.

What this error means

The step is killed with a timeout/cancellation message after running long, often during Wait-Job, a network wait, or a heavy build. Intermittent when the cause is a transient stall.

powershell
Wait-Job : The job has not completed within the timeout period.
##[error]The operation was canceled.
##[error]The job running on runner ... has exceeded the maximum execution time.

Common causes

No explicit timeout, so the default kills it

Without a bounded Wait-Job timeout or a step timeout-minutes, a stalled job runs until the job-level limit, wasting time before failing.

A transient stall in a network or external dependency

A hung download, registry call, or external service can stall the job until the runner cancels it, even though a retry would succeed quickly.

How to fix it

Bound the wait and fail fast

Give Wait-Job a timeout so a stall fails quickly and can be retried instead of burning the whole budget.

powershell
$job = Start-Job { ./long-task.ps1 }
if (-not (Wait-Job $job -Timeout 600)) {
  Stop-Job $job; throw 'job timed out'
}
Receive-Job $job

Set a step-level timeout

Cap the step so a hang does not consume the whole job limit.

cmd
- name: Long task
  timeout-minutes: 15
  shell: pwsh
  run: ./long-task.ps1

How to prevent it

  • Bound waits with explicit timeouts and set step timeout-minutes. Transient stalls are common; on Latchkey managed runners self-healing auto-retries transient timeout-class failures so a one-off stall does not fail the job. Windows minutes bill at roughly 2x Linux, so move long, slow steps to Linux where the work allows.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →