Stay organized with collections
Save and categorize content based on your preferences.
Function timeout
If a function runs for too long, the system takes steps to terminate or
throttle it. This timeout period defaults to
60 seconds, but you can extend or
reduce it when you deploy the function. The maximum timeout duration is 60
minutes
(3600 seconds) for HTTP functions and 9 minutes (540 seconds) for event-driven functions.
When function execution reaches its timeout, a response message with an HTTP 504
error status is immediately returned to the caller. The function instance might
be throttled, but it continues operating until it exits on its own. Any response
message that the function generates is discarded and not returned to the caller.
This behavior can cause unexpected side effects. A common
symptom is the appearance of work and logs from one request "leaking" into a
subsequent request. To avoid this, prevent timeouts in your functions with the
following techniques:
Set a timeout higher than your expected function execution time.
Track the amount of time left during execution. Then perform cleanup and
return early.
Set a timeout duration
To set a function's timeout duration at deployment with the
Google Cloud CLI, use the
--timeout flag:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-03-21 UTC."],[[["Functions have a default timeout of 60 seconds, which can be adjusted during deployment, up to 60 minutes for HTTP functions and 9 minutes for event-driven functions."],["Upon timeout, a 504 error is returned to the caller, while the function continues to run internally, discarding any generated responses."],["Event-driven functions with disabled retry return a 200 status regardless of execution outcome, which can lead to issues."],["To avoid timeouts, set a timeout higher than the expected execution time, and implement internal time tracking with early cleanup and return."],["The `--timeout` flag in the Google Cloud CLI is used to set or change a function's timeout during deployment or redeployment."]]],[]]