Setting request timeout (services)

Stay organized with collections Save and categorize content based on your preferences.

For Cloud Run services, the request timeout setting specifies the time within which a response must be returned by services deployed to Cloud Run. If a response isn't returned within the time specified, the request ends and error 504 is returned.

The timeout is set by default to 5 minutes and can be extended up to 60 minutes.

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.

Setting and updating 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 Google Cloud console, the gcloud command line, or a YAML file when you create a new service or deploy a new revision.

Console

  1. Go to Cloud Run

  2. Click Create Service if you are configuring a new service you are deploying to. If you are configuring an existing service, click on the service, then click Edit and Deploy New Revision.

  3. If you are configuring a new service, fill out the initial service settings page as desired, then click Container, connections, security to expand the service configuration page.

  4. Click the Container tab.

    image

  5. In the Request timeout field, enter the timeout value that you want to use in seconds. Use values ranging from 1 to 3600 seconds, or from 1 to 60 minutes.

  6. Click Create or Deploy.

Command line

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

  • [SERVICE] with the name of your service.
  • [TIMEOUT] with the desired time, using an integer value or an absolute duration value, for example 1m20s which 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

  • IMAGE_URL with a reference to the container image, for example, us-docker.pkg.dev/cloudrun/container/hello:latest
  • [TIMEOUT] with the desired time, using an integer value or a duration value, for example 1m20s which 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

You can download and view existing service configuration using the gcloud run services describe --format export command, which yields cleaned results in YAML format. You can then modify the fields described below and upload the modified YAML using the gcloud run services replace command. Make sure you only modify fields as documented.

  1. To view and download the configuration:

    gcloud run services describe SERVICE --format export > service.yaml
  2. Update the timeoutSeconds attribute:

    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: SERVICE
    spec:
      template:
        metadata:
          name: REVISION
        spec:
          containers:
          - image: IMAGE
          timeoutSeconds: VALUE

    Replace

    • SERVICE with the name of your Cloud Run service
    • IMAGE_URL with a reference to the container image, for example, us-docker.pkg.dev/cloudrun/container/hello:latest
    • VALUE with the desired timeout, in seconds.
    • REVISION with a new revision name or delete it (if present). If you supply a new revision name, it must meet the following criteria:
      • Starts with SERVICE-
      • Contains only lowercase letters, numbers and -
      • Does not end with a -
      • Does not exceed 63 characters
  3. Replace the service with its new configuration using the following command:

    gcloud run services replace service.yaml

Terraform

Add the following to a google_cloud_run_service resource in your Terraform configuration, under template.spec. Replace 300 with your service's desired request timeout (in seconds).

# Timeout
# https://cloud.google.com/run/docs/configuring/request-timeout
timeout_seconds = 300

To apply your Terraform configuration in a Google Cloud project, complete the following steps:

  1. Launch Cloud Shell.
  2. Set the Google Cloud project where you want to apply the Terraform configuration:
    export GOOGLE_CLOUD_PROJECT=PROJECT_ID
    
  3. Create a directory and open a new file in that directory. The filename must have the .tf extension, for example main.tf:
    mkdir DIRECTORY && cd DIRECTORY && nano main.tf
    
  4. Copy the sample into main.tf.
  5. Review and modify the sample parameters to apply to your environment.
  6. Save your changes by pressing Ctrl-x and then y.
  7. Initialize Terraform:
    terraform init
  8. Review the configuration and verify that the resources that Terraform is going to create or update match your expectations:
    terraform plan

    Make corrections to the configuration as necessary.

  9. Apply the Terraform configuration by running the following command and entering yes at the prompt:
    terraform apply

    Wait until Terraform displays the "Apply complete!" message.

  10. Open your Google Cloud project to view the results. In the Google Cloud console, navigate to your resources in the UI to make sure that Terraform has created or updated them.

View request timeout settings

To view the current request timeout settings for your Cloud Run service:

Console

  1. Go to Cloud Run

  2. Click the service you are interested in to open the Service details page.

  3. Click the Revisions tab.

  4. In the details panel at the right, the request timeout setting is listed under the Container tab.

Command line

  1. Use the following command:

    gcloud run services describe SERVICE
  2. Locate the request timeout setting in the returned configuration.