Skip to main content

timeout

Set a maximum execution time for a module call.

Syntax

result = Module(args) with timeout: <duration>

Type: Duration (ms, s, min, h, d)

Description

The timeout option sets the maximum time a module call can execute before being cancelled. When combined with retry, the timeout applies per attempt, not to the total execution time.

Timeout is per attempt, not total

With timeout: 10s, retry: 3, each of the 4 attempts has a 10-second limit. The total maximum time is 40 seconds (plus any delays between retries). Plan accordingly for SLA budgets.

Always set timeouts for network calls

Network operations (HTTP, database, external APIs) should always have explicit timeouts. Without one, a stalled connection can block indefinitely and exhaust resources.

Examples

Basic Timeout

response = HttpRequest(url) with timeout: 30s

If the request takes longer than 30 seconds, it's cancelled with a timeout error.

Timeout with Retry

result = RemoteCall(params) with timeout: 10s, retry: 3

Each of the 4 possible attempts (1 initial + 3 retries) has a 10-second timeout. Maximum total time: 40 seconds.

Short Timeout for Fast Services

cached = GetFromCache(key) with timeout: 100ms

Fail fast if the cache doesn't respond within 100ms.

Timeout with Fallback

data = SlowOperation(input) with timeout: 5s, fallback: defaultData

If the operation times out, use defaultData instead of failing.

Behavior

  1. Start the module execution
  2. Start a timer for the specified duration
  3. If the module completes before the timer:
    • Cancel the timer
    • Return the result
  4. If the timer fires before the module completes:
    • Cancel the module execution
    • Raise ModuleTimeoutException

Error Details

When a timeout occurs, a ModuleTimeoutException is raised containing:

  • Module name
  • Timeout duration
  • Descriptive message

Example error message:

Module HttpRequest timed out after 30s

Duration Units

UnitSuffixExample
Millisecondsms100ms, 500ms
Secondss1s, 30s
Minutesmin1min, 5min
Hoursh1h, 2h
Daysd1d
  • retry - Retry after timeout
  • fallback - Default value on timeout
  • delay - Wait between retried timeouts

Best Practices

  • Always set a timeout for network operations
  • Use shorter timeouts with retry for transient failures
  • Consider the downstream impact of long timeouts
  • Set timeouts based on expected response times plus margin