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). You can change this setting
when you deploy a container image or update the service configuration.

> [!IMPORTANT]
> **Important:** For a timeout longer than 15 minutes, we recommend implementing retries and making sure the service is tolerant to clients reconnecting if the connection is lost. For example, make sure that requests are idempotent, or design request handlers so that they can resume from the point where they left off. The longer the timeout is, the more likely the connection can be lost due to failures on the client side or the Cloud Run side. When a client reconnects, a new request is initiated and the client isn't guaranteed to connect to the same instance of the service.

When triggering your service from
[Eventarc events](https://docs.cloud.google.com/run/docs/triggering/trigger-with-events.md.txt),
[Pub/Sub push subscriptions](https://docs.cloud.google.com/run/docs/triggering/pubsub-triggers.md.txt),
[Cloud Scheduler](https://docs.cloud.google.com/run/docs/triggering/using-scheduler.md.txt),
[Cloud Tasks](https://docs.cloud.google.com/run/docs/triggering/using-tasks.md.txt), or
[Workflows](https://docs.cloud.google.com/workflows/docs/calling-run-functions.md.txt), the timeouts of
those services apply. For example:

- Pub/Sub push subscriptions (both direct triggers and
  Eventarc triggers) have a default
  [acknowledgment deadline](https://docs.cloud.google.com/run/docs/triggering/trigger-with-events.md.txt#set-ack-deadline)
  of 10 seconds and a maximum of 10 minutes (600
  seconds).

- Cloud Scheduler HTTP targets (3-minute default),
  Cloud Tasks HTTP targets (10-minute default), and synchronous
  Workflows HTTP requests (5-minute default) have a maximum timeout
  of 30 minutes (1,800 seconds).

- For workloads invoked by Workflows that run longer than 30
  minutes, use
  [Cloud Run jobs](https://docs.cloud.google.com/workflows/docs/calling-run-functions.md.txt#cloud-run-jobs)
  or [callback endpoints](https://docs.cloud.google.com/workflows/docs/creating-callback-endpoints.md.txt).

In addition to changing the Cloud Run request timeout, check your
language framework to see whether it has its own request timeout setting that
you must 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](https://docs.cloud.google.com/iam/docs/roles-permissions/run.md.txt#run.developer) (`roles/run.developer`) on the Cloud Run service
- [Service Account User](https://docs.cloud.google.com/iam/docs/roles-permissions/iam.md.txt#iam.serviceAccountUser) (`roles/iam.serviceAccountUser`) on the service identity


If you are deploying a [service](https://docs.cloud.google.com/run/docs/deploying-source-code.md.txt#required_roles)
or [function](https://docs.cloud.google.com/run/docs/deploy-functions.md.txt#required-roles) 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](https://docs.cloud.google.com/run/docs/reference/iam/roles.md.txt)
and [Cloud Run IAM permissions](https://docs.cloud.google.com/run/docs/reference/iam/permissions.md.txt).
If your Cloud Run service interfaces with
Google Cloud APIs, such as Cloud Client Libraries, see the
[service identity configuration guide](https://docs.cloud.google.com/run/docs/configuring/services/service-identity.md.txt).
For more information about granting roles, see
[deployment permissions](https://docs.cloud.google.com/run/docs/reference/iam/roles.md.txt#additional-configuration)
and [manage access](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).

## 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 Google Cloud console, the gcloud CLI
command line, or a YAML file when you [create a new service](https://docs.cloud.google.com/run/docs/deploying.md.txt#service) or
[deploy a new revision](https://docs.cloud.google.com/run/docs/deploying.md.txt#revision).

### Console

1. In the Google Cloud console, go to Cloud Run:

   [Go to Cloud Run](https://console.cloud.google.com/run)
2. Select **Services** from the Cloud Run navigation menu:

   1. If you are configuring a new service, click **Deploy container** and
      fill out the initial service settings page. Then click
      **Containers, Networking, Security** to expand the service configuration page.

   2. If you are configuring an existing service, click the service, then
      click the **Scaling** tab.

3. Under **Requests** , in the **Request timeout** field, enter the timeout
   value that you want to use in seconds. Use values ranging from `1` to
   `3600` seconds.

4. Click **Create** for a new service. Click **View diff \& redeploy** , then **Deploy changes** for an existing service.

### gcloud

You can [update the request timeout](https://docs.cloud.google.com/sdk/gcloud/reference/run/services/update.md.txt)
for a given revision at any time by using the following command:

```bash
gcloud run services update SERVICE --timeout=TIMEOUT
```

Replace the following:

- <var translate="no">SERVICE</var>: the name of your service.
- <var translate="no">TIMEOUT</var>: the time within which a response must be
  returned, using an integer value or an
  [absolute duration value](https://docs.cloud.google.com/sdk/gcloud/reference/topic/datetimes)---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.

  > [!NOTE]
  > **Note:** When you update your service with the new timeout value, a new revision is created.

You can also set the request timeout during
[deployment](https://docs.cloud.google.com/sdk/gcloud/reference/run/deploy.md.txt) using the command:

```bash
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](https://docs.cloud.google.com/artifact-registry/docs/repositories/create-repos.md.txt#docker) <var translate="no">REPO_NAME</var> must already be created. The URL follows the format of `LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG` .
- <var translate="no">TIMEOUT</var>: the time within which a response must be returned, 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

1. If you are creating a new service, skip this step.
   If you are updating an existing service, download its [YAML configuration](https://docs.cloud.google.com/run/docs/reference/yaml/v1.md.txt):

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

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

   Replace the following:
   - <var translate="no">SERVICE</var>: 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](https://docs.cloud.google.com/artifact-registry/docs/repositories/create-repos.md.txt#docker) <var translate="no">REPO_NAME</var> must already be created. The URL follows the format of `LOCATION-docker.pkg.dev/PROJECT_ID/REPO_NAME/PATH:TAG` .
   - <var translate="no">VALUE</var>: the chosen timeout, in seconds.
3. Create or update the service using the following command:

   ```bash
   gcloud run services replace service.yaml
   ```

   The `gcloud run services replace` command defaults to using `service.yaml` file if present.

### Terraform


To learn how to apply or remove a Terraform configuration, see
[Basic Terraform commands](https://docs.cloud.google.com/docs/terraform/basic-commands.md.txt).
Add the following to a [`google_cloud_run_v2_service`](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloud_run_v2_service) resource in your Terraform configuration:  

<br />

```terraform
resource "google_cloud_run_v2_service" "default" {
  name     = "cloudrun-service-request-timeout"
  location = "us-central1"

  deletion_protection = false # set to "true" in production

  template {
    containers {
image = "us-docker.pkg.dev/cloudrun/container/hello"
}
    # Timeout
    timeout = "300s"
  }
}
```

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

1. In the Google Cloud console, go to the Cloud Run **Services** page:

   [Go to Cloud Run](https://console.cloud.google.com/run/services)
2. Click the service you are interested in to open the **Service details**
   page.

3. Click the **Scaling** tab to view the settings.

### gcloud

1. Use the following command:

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