Cloud Run request timeout settings let you define the maximum time a service has to return a response. If your service doesn't respond within this limit, Cloud Run closes the network connection and returns an HTTP 504 error.
Closing the connection doesn't terminate the container instance. The container might continue processing the aborted request, which can interfere with handling other requests. To prevent timeouts, set a timeout higher than your expected execution time, or track the remaining execution time to perform cleanup and return early.
Timeout period for services
The timeout is set by default to 5 minutes (300 seconds) and can be extended up to 60 minutes (3600 seconds).
When triggering your service from Eventarc events, Pub/Sub push subscriptions or Cloud Scheduler, the timeout of these services apply.
You can change this setting when you deploy a container image or by updating the service configuration.
In addition to changing the Cloud Run request timeout, you should also check your language framework to see whether it has its own request timeout setting that you must also update. Some clients of the Cloud Run service might also impose a more restrictive timeout.
Required roles
To get the permissions that you need to configure and deploy Cloud Run services, ask your administrator to grant you the following IAM roles:
- Cloud Run Developer (
roles/run.developer) on the Cloud Run service - Service Account User (
roles/iam.serviceAccountUser) on the service identity
If you are deploying a service or function from source code, you must also have additional roles granted to you on your project and Cloud Build service account.
For a list of IAM roles and permissions that are associated with Cloud Run, see Cloud Run IAM roles and Cloud Run IAM permissions. If your Cloud Run service interfaces with Cloud de Confiance APIs, such as Cloud Client Libraries, see the service identity configuration guide. For more information about granting roles, see deployment permissions and manage access.
Set and update request timeout
Any configuration change leads to the creation of a new revision. Subsequent revisions will also automatically get this configuration setting unless you make explicit updates to change it.
You can set request timeout using the Cloud de Confiance console, the gcloud CLI command line, or a YAML file when you create a new service or deploy a new revision.
Console
In the Cloud de Confiance by S3NS console, go to Cloud Run:
Select Services from the Cloud Run navigation menu, and click Deploy container to configure a new service. If you are configuring an existing service, click the service.
If you are configuring a new service, fill out the initial service settings page, then click Containers, Networking, Security to expand the service configuration page.
If you are configuring an existing service, click the Scaling tab.
Under Requests, in the Request timeout field, enter the timeout value that you want to use in seconds. Use values ranging from
1to3600seconds.Click Create for a new service. Click View diff & redeploy, then Deploy changes for an existing service.
gcloud
You can update the request timeout for a given revision at any time by using the following command:
gcloud run services update SERVICE --timeout=TIMEOUT
Replace the following:
- SERVICE: the name of your service.
TIMEOUT: the time within which a response must be returned, using an integer value or an absolute duration value—for example
1m20swhich is 1 minute, 20 seconds. If you use an integer value, the unit is assumed to be seconds. The value you specify must be less than 60 minutes.
You can also set the request timeout during deployment using the command:
gcloud run deploy --image IMAGE_URL --timeout=TIMEOUT
Replace the following:
IMAGE_URL: a reference to the container image, for example,us-docker.pkg.dev/cloudrun/container/hello:latest. If you use Artifact Registry, the repository REPO_NAME must already be created. The URL follows the format ofLOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG.- TIMEOUT: the time within which a response must be
returned, using an integer value or a duration value—for example,
1m20swhich is 1 minute, 20 seconds. If you use an integer value, the unit is assumed to be seconds. The value you specify must be less than 60 minutes.
YAML
If you are creating a new service, skip this step. If you are updating an existing service, download its YAML configuration:
gcloud run services describe SERVICE --format export > service.yaml
Update the
timeoutSecondsattribute:apiVersion: serving.knative.dev/v1 kind: Service metadata: name: SERVICE spec: template: spec: containers: - image: IMAGE timeoutSeconds: VALUE
Replace the following:
- SERVICE: the name of your Cloud Run service.
IMAGE_URL: a reference to the container image, for example,us-docker.pkg.dev/cloudrun/container/hello:latest. If you use Artifact Registry, the repository REPO_NAME must already be created. The URL follows the format ofLOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG.- VALUE: the chosen timeout, in seconds.
Create or update the service using the following command:
gcloud run services replace service.yaml
The
gcloud run services replacecommand defaults to usingservice.yamlfile if present.
Terraform
To learn how to apply or remove a Terraform configuration, see Basic Terraform commands.
Add the following to agoogle_cloud_run_v2_service
resource in your Terraform configuration:Replace 300s with your service's chosen request timeout.
View request timeout settings
To view the current request timeout settings for your Cloud Run service:
Console
In the Cloud de Confiance by S3NS console, go to the Cloud Run Services page:
Click the service you are interested in to open the Service details page.
Click the Scaling tab to view the settings.
gcloud
Use the following command:
gcloud run services describe SERVICE
Locate the request timeout setting in the returned configuration.