Function timeout

Function execution time is limited by the timeout duration, which you can specify when you deploy a function. By default, a function times out after one minute (60 seconds), but you can extend this period:

  • In Cloud Functions (1st gen), the maximum timeout duration is nine minutes (540 seconds).
  • In Cloud Functions (2nd gen), the maximum timeout duration is 60 minutes (3600 seconds) for HTTP functions and 9 minutes (540 seconds) for event-driven functions.

When function execution exceeds the timeout, an error status is immediately returned to the caller. CPU resources used by the timed-out function instance are throttled and request processing is paused.

In some circumstances, paused work might continue in the background or resume upon a subsequent request, which can cause unexpected side effects. A common symptom of this behavior is the appearance that work and logs from one request are "leaking" into a subsequent request. Because you cannot depend on paused work being resumed, you must not rely on this behavior. Instead, your function should avoid timeouts using a combination of the following techniques:

  1. Set a timeout that is higher than your expected function execution time.
  2. Track the amount of time left during execution and perform cleanup/exit early.

Set a timeout duration

You can set a function's timeout duration at deployment using the Google Cloud CLI or the Google Cloud console.


If you are deploying using the gcloud CLI, use the --timeout flag:

gcloud functions deploy YOUR_FUNCTION_NAME --timeout=TIMEOUT_DURATION ...

To edit an existing timeout duration with Google Cloud CLI, simply redeploy the function with a new timeout value.


To set the timeout duration during function creation in the Google Cloud console:

  1. Go to the Cloud Functions Overview page in the Google Cloud console.
  2. Click Create function.
  3. Fill in the required fields for your function.
  4. Expand the Runtime, build... section at the end of the page and click the Runtime tab.
  5. In the Timeout field, enter a number of seconds.

    To edit an existing timeout duration in Google Cloud console, on the functions overview page click the name of the desired function to go to its details page. On the details page click Edit, expand the Runtime, build... section, and click the Runtime tab, where you can directly edit the value in the Timeout field.