A timeout defines the maximum duration a runnable task is allowed to run.

What is a timeout

If a task run exceeds the specified duration, Kestra automatically stops it and marks it as failed. This is useful for tasks that may hang and run indefinitely.

Timeouts are often used as a cost-control mechanism in cloud-based workflows. Imagine a Snowflake query or an AWS Batch job that runs for hours leading to unexpected costs. By setting a timeout, you can ensure that the task run will not exceed a certain duration.

Format

Similar to retries, timeouts use the ISO 8601 duration format, but week, month, and year designators are not supported. Below are some examples:

namedescription
PT0.250S250 milliseconds delay
PT2S2 seconds delay
PT1M1 minute delay
PT3.5H3 hours and a half delay
P6DT4H6 days and 4 hours delay

Example

In this example, the costly_query task sleeps for 10 seconds, but the timeout is set to 5 seconds, causing the task to fail.

yaml
id: timeout
namespace: company.team
description: This flow will always fail because of a timeout.

tasks:
  - id: costly_query
    type: io.kestra.plugin.scripts.shell.Commands
    taskRunner:
      type: io.kestra.plugin.core.runner.Process
    commands:
      - sleep 10
    timeout: PT5S

Flow-level timeout

There is no flow-level timeout. To cancel a workflow execution that exceeds a specific duration, use MAX_DURATION-type SLA.

Was this page helpful?