What can I do if my function exceeds the timeout period?

Updated at:
Copy as MD

Function Compute supports a maximum execution time of 24 hours per function. If your function consistently hits the timeout limit, the fix depends on what is causing the slowdown.

Common causes

Functions typically time out for one of the following reasons:

CauseDescription
Large input dataProcessing a large file or dataset takes longer than expected
Slow downstream dependenciesA database query, external API call, or storage read takes too long to return
Heavy computationThe function performs CPU-intensive work that exceeds available resources
Unoptimized codeInefficient loops, redundant operations, or missing caching

Solutions

Work through these options in order, from least invasive to most architectural.

1. Increase the timeout setting

If the function is close to completing but just needs more time, increase the timeout in the function configuration. The maximum is 24 hours.

2. Profile and optimize the function

Before restructuring your architecture, check whether the function can finish faster:

  • Add logging around slow operations to identify bottlenecks.

  • Cache results of repeated computations or lookups.

  • Reduce the size of data processed in a single invocation.

  • If the function is memory- or CPU-constrained, increase the resource allocation in the function configuration.

3. Split the function

If the function handles too much work in a single invocation, split it into smaller functions that each complete within the timeout period.

A common pattern for long-running tasks is to defer work through a queue:

  1. An entry function receives the request and writes the task to a message queue.

  2. A worker function picks up the task asynchronously and processes it.

  3. The entry function returns immediately, without waiting for the result.

This keeps each function within the timeout limit and prevents blocking the caller.

4. Orchestrate with CloudFlow

For complex workflows that span multiple functions or require coordination across steps, use CloudFlow. A CloudFlow flow can run for up to one year, making it suitable for long-running or multi-stage processing pipelines.

Get support

If none of the above resolves the issue, join the DingTalk group (ID: 11721331) for Function Compute technical support.