> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gcore.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Customize connection and read timeouts

> Configure custom connection and read timeouts for Gcore CDN resources to control origin waits and avoid 504 Gateway Timeout errors.

## Customer Portal

Custom connection and read timeouts control how long Gcore edge nodes wait when communicating with an origin server.

* A custom connection timeout sets the maximum duration allowed for establishing a connection.

* A custom read timeout sets the maximum time Gcore edge nodes wait for the next data from the origin after a read. It does not limit the total response transmission time.

When a configured timeout is exceeded, the viewer receives a 504 Gateway Timeout response.

## Configure custom timeouts

Timeouts are configured per CDN resource and apply to all requests handled by that resource.

1\. In the [Gcore Customer Portal](https://portal.gcore.com), navigate to **CDN** > **CDN resources**.

![CDN resources list page](https://mintcdn.com/gcore/etpB_hN3OF7K7B6S/images/docs/cdn/cdn-resource-options/general/customize-connection-and-read-timeouts/cdn-resources.png?fit=max\&auto=format\&n=etpB_hN3OF7K7B6S\&q=85\&s=54dae98b48dbe78a23f1349896cd568c)

2\. Click the CNAME of the required CDN resource to open **Resource settings**.

![Custom connection timeout and Custom read timeout options in the resource settings](https://mintcdn.com/gcore/etpB_hN3OF7K7B6S/images/docs/cdn/cdn-resource-options/general/customize-connection-and-read-timeouts/resource-settings.png?fit=max\&auto=format\&n=etpB_hN3OF7K7B6S\&q=85\&s=089194a74e47d9dba435a319486edb1e)

3\. Click **Custom connection timeout** or **Custom read timeout**, depending on the timeout to configure.

4\. Enable the **Customize connection timeout** or **Customize read timeout** toggle.

5\. Enter the timeout value. The allowed range is `1–5 seconds` for connection timeout and `1–30 seconds` for read timeout. To configure both timeouts, repeat steps 3–5 for the other option before saving.

> [!NOTE]
>
> For Enterprise plans, the upper limits can be raised beyond 5 seconds (connection) and 30 seconds (read). Contact [Gcore Support](https://support.gcore.com/hc/en-us/requests/new) to request higher values.

![Resource settings showing both custom timeout toggles enabled with values entered](https://mintcdn.com/gcore/etpB_hN3OF7K7B6S/images/docs/cdn/cdn-resource-options/general/customize-connection-and-read-timeouts/enable-connection-read-timeouts.png?fit=max\&auto=format\&n=etpB_hN3OF7K7B6S\&q=85\&s=cb4432922af43f6852a664154ad6bccc)

6\. Click **Save changes**.

## REST API

A slow origin holds the viewer request while Gcore CDN waits to connect or to receive the next part of the response. `proxy_connect_timeout` limits the wait to open the connection, and `proxy_read_timeout` limits the wait between successive reads, not the time for the whole response. After either limit is reached, the viewer receives a 504 Gateway Timeout response.

> [!NOTE]
>
> An [API token](https://docs.gcore.com/account-settings/api-tokens.md) is required. The CDN resource ID is the `id` from the [resources list](https://docs.gcore.com/api-reference/cdn/cdn-resources/list-cdn-resources) call.

```bash theme={null}
export GCORE_API_KEY="{YOUR_API_KEY}"
export CDN_RESOURCE_ID="{YOUR_CDN_RESOURCE_ID}"
```

## Set the connection timeout

Set `value` to a duration from 1 second through 5 seconds. `enabled` and `value` are both required.

The API accepts `4s` and `4`. `0s`, `6s`, `4S`, `4sec`, and `4000ms` return HTTP 400.

> [tab] Python SDK
>
> ```python theme={null}
> import os
>
> from gcore import Gcore
>
> client = Gcore()
> resource_id = int(os.environ["CDN_RESOURCE_ID"])
>
> updated = client.cdn.cdn_resources.update(
>     resource_id,
>     options={"proxy_connect_timeout": {"enabled": True, "value": "4s"}},
> )
> print(updated.options.proxy_connect_timeout.enabled, updated.options.proxy_connect_timeout.value)
> ```

> [tab] Go SDK
>
> ```go theme={null}
> package main
>
> import (
>     "context"
>     "fmt"
>     "os"
>     "strconv"
>
>     gcore "github.com/G-Core/gcore-go"
>     "github.com/G-Core/gcore-go/cdn"
> )
>
> func main() {
>     client := gcore.NewClient()
>     ctx := context.Background()
>     resourceID, err := strconv.ParseInt(os.Getenv("CDN_RESOURCE_ID"), 10, 64)
>     if err != nil {
>         panic(err)
>     }
>
>     updated, err := client.CDN.CDNResources.Update(ctx, resourceID, cdn.CDNResourceUpdateParams{
>         Options: cdn.CDNResourceUpdateParamsOptions{
>             ProxyConnectTimeout: cdn.CDNResourceUpdateParamsOptionsProxyConnectTimeout{
>                 Enabled: true,
>                 Value:   "4s",
>             },
>         },
>     })
>     if err != nil {
>         panic(err)
>     }
>     fmt.Println(updated.Options.ProxyConnectTimeout.Enabled, updated.Options.ProxyConnectTimeout.Value)
> }
> ```

> [tab] curl
>
> ```bash theme={null}
> curl -X PATCH "https://api.gcore.com/cdn/resources/$CDN_RESOURCE_ID" \
>   -H "Authorization: APIKey $GCORE_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "options": {
>       "proxy_connect_timeout": {"enabled": true, "value": "4s"}
>     }
>   }'
> ```
>
> The API returns HTTP 200. The saved option is:
>
> ```json theme={null}
> {
>   "enabled": true,
>   "value": "4s"
> }
> ```

## Set the read timeout

Set `value` to a duration from 1 second through 30 seconds. `enabled` and `value` are both required. The API accepts `10s` and `10`. `0s`, `31s`, `10S`, `10sec`, and `10000ms` return HTTP 400.

> [tab] Python SDK
>
> ```python theme={null}
> import os
>
> from gcore import Gcore
>
> client = Gcore()
> resource_id = int(os.environ["CDN_RESOURCE_ID"])
>
> updated = client.cdn.cdn_resources.update(
>     resource_id,
>     options={"proxy_read_timeout": {"enabled": True, "value": "10s"}},
> )
> print(updated.options.proxy_read_timeout.enabled, updated.options.proxy_read_timeout.value)
> ```

> [tab] Go SDK
>
> ```go theme={null}
> package main
>
> import (
>     "context"
>     "fmt"
>     "os"
>     "strconv"
>
>     gcore "github.com/G-Core/gcore-go"
>     "github.com/G-Core/gcore-go/cdn"
> )
>
> func main() {
>     client := gcore.NewClient()
>     ctx := context.Background()
>     resourceID, err := strconv.ParseInt(os.Getenv("CDN_RESOURCE_ID"), 10, 64)
>     if err != nil {
>         panic(err)
>     }
>
>     updated, err := client.CDN.CDNResources.Update(ctx, resourceID, cdn.CDNResourceUpdateParams{
>         Options: cdn.CDNResourceUpdateParamsOptions{
>             ProxyReadTimeout: cdn.CDNResourceUpdateParamsOptionsProxyReadTimeout{
>                 Enabled: true,
>                 Value:   "10s",
>             },
>         },
>     })
>     if err != nil {
>         panic(err)
>     }
>     fmt.Println(updated.Options.ProxyReadTimeout.Enabled, updated.Options.ProxyReadTimeout.Value)
> }
> ```

> [tab] curl
>
> ```bash theme={null}
> curl -X PATCH "https://api.gcore.com/cdn/resources/$CDN_RESOURCE_ID" \
>   -H "Authorization: APIKey $GCORE_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "options": {
>       "proxy_read_timeout": {"enabled": true, "value": "10s"}
>     }
>   }'
> ```
>
> The API returns HTTP 200. The saved option is:
>
> ```json theme={null}
> {
>   "enabled": true,
>   "value": "10s"
> }
> ```

## Set both timeouts

Send both options in one request. The call sets the connection timeout to `4s` and the read timeout to `10s`.

> [tab] Python SDK
>
> ```python theme={null}
> import os
>
> from gcore import Gcore
>
> client = Gcore()
> resource_id = int(os.environ["CDN_RESOURCE_ID"])
>
> updated = client.cdn.cdn_resources.update(
>     resource_id,
>     options={
>         "proxy_connect_timeout": {"enabled": True, "value": "4s"},
>         "proxy_read_timeout": {"enabled": True, "value": "10s"},
>     },
> )
> print(
>     updated.options.proxy_connect_timeout.value,
>     updated.options.proxy_read_timeout.value,
> )
> ```

> [tab] Go SDK
>
> ```go theme={null}
> package main
>
> import (
>     "context"
>     "fmt"
>     "os"
>     "strconv"
>
>     gcore "github.com/G-Core/gcore-go"
>     "github.com/G-Core/gcore-go/cdn"
> )
>
> func main() {
>     client := gcore.NewClient()
>     ctx := context.Background()
>     resourceID, err := strconv.ParseInt(os.Getenv("CDN_RESOURCE_ID"), 10, 64)
>     if err != nil {
>         panic(err)
>     }
>
>     updated, err := client.CDN.CDNResources.Update(ctx, resourceID, cdn.CDNResourceUpdateParams{
>         Options: cdn.CDNResourceUpdateParamsOptions{
>             ProxyConnectTimeout: cdn.CDNResourceUpdateParamsOptionsProxyConnectTimeout{
>                 Enabled: true,
>                 Value:   "4s",
>             },
>             ProxyReadTimeout: cdn.CDNResourceUpdateParamsOptionsProxyReadTimeout{
>                 Enabled: true,
>                 Value:   "10s",
>             },
>         },
>     })
>     if err != nil {
>         panic(err)
>     }
>     fmt.Println(updated.Options.ProxyConnectTimeout.Value, updated.Options.ProxyReadTimeout.Value)
> }
> ```

> [tab] curl
>
> ```bash theme={null}
> curl -X PATCH "https://api.gcore.com/cdn/resources/$CDN_RESOURCE_ID" \
>   -H "Authorization: APIKey $GCORE_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "options": {
>       "proxy_connect_timeout": {"enabled": true, "value": "4s"},
>       "proxy_read_timeout": {"enabled": true, "value": "10s"}
>     }
>   }'
> ```
>
> The API returns HTTP 200. The saved options are:
>
> ```json theme={null}
> {
>   "proxy_connect_timeout": {
>     "enabled": true,
>     "value": "4s"
>   },
>   "proxy_read_timeout": {
>     "enabled": true,
>     "value": "10s"
>   }
> }
> ```

## Turn the timeouts off

Set both options to `null`. The saved resource then has neither timeout. `enabled` set to `false` keeps the duration and turns that timeout off.

> [tab] Python SDK
>
> ```python theme={null}
> import os
>
> from gcore import Gcore
>
> client = Gcore()
> resource_id = int(os.environ["CDN_RESOURCE_ID"])
>
> updated = client.cdn.cdn_resources.update(
>     resource_id,
>     options={"proxy_connect_timeout": None, "proxy_read_timeout": None},
> )
> print(updated.options.proxy_connect_timeout, updated.options.proxy_read_timeout)
> ```

> [tab] Go SDK
>
> ```go theme={null}
> package main
>
> import (
>     "context"
>     "fmt"
>     "os"
>     "strconv"
>
>     gcore "github.com/G-Core/gcore-go"
>     "github.com/G-Core/gcore-go/cdn"
> )
>
> func main() {
>     client := gcore.NewClient()
>     ctx := context.Background()
>     resourceID, err := strconv.ParseInt(os.Getenv("CDN_RESOURCE_ID"), 10, 64)
>     if err != nil {
>         panic(err)
>     }
>
>     options := cdn.CDNResourceUpdateParamsOptions{}
>     options.SetExtraFields(map[string]any{
>         "proxy_connect_timeout": nil,
>         "proxy_read_timeout":    nil,
>     })
>     updated, err := client.CDN.CDNResources.Update(ctx, resourceID, cdn.CDNResourceUpdateParams{
>         Options: options,
>     })
>     if err != nil {
>         panic(err)
>     }
>     fmt.Println(updated.Options.ProxyConnectTimeout.RawJSON(), updated.Options.ProxyReadTimeout.RawJSON())
> }
> ```

> [tab] curl
>
> ```bash theme={null}
> curl -X PATCH "https://api.gcore.com/cdn/resources/$CDN_RESOURCE_ID" \
>   -H "Authorization: APIKey $GCORE_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "options": {
>       "proxy_connect_timeout": null,
>       "proxy_read_timeout": null
>     }
>   }'
> ```
>
> The API returns HTTP 200. The saved options are:
>
> ```json theme={null}
> {
>   "proxy_connect_timeout": null,
>   "proxy_read_timeout": null
> }
> ```

## Terraform

Limit how long CDN servers wait on the origin with the [Terraform provider](https://docs.gcore.com/developer-tools/terraform/overview.md) v2. `proxy_connect_timeout` is the wait to open the connection, and `proxy_read_timeout` is the wait between successive reads. After either limit is reached, the viewer receives a 504 Gateway Timeout response. Run `terraform apply` after editing `options`.

## Connection and read timeouts

Set both options `enabled` to `true`, `proxy_connect_timeout` `value` to `4s`, and `proxy_read_timeout` `value` to `10s`. CDN servers then wait 4 seconds to open the origin connection and 10 seconds between successive reads. Connection durations of `1s`, `4s`, and `5s`, and read durations of `1s`, `10s`, and `30s`, are stored in the same format.

`0s` returns HTTP 400: `Value must be more 1.` A connection value of `6s` returns HTTP 400: `Value must be less or equal 5s.` A read value of `31s` returns HTTP 400: `Value must be less or equal 30s.` Set `enabled` to `false` to disable a timeout while keeping the saved duration.

```hcl theme={null}
resource "gcore_cdn_origin_group" "example" {
  name = "my-origin-group"

  sources = [
    {
      source  = "example.com"
      enabled = true
    }
  ]
}

resource "gcore_cdn_resource" "example" {
  cname           = "cdn.example.com"
  origin_group    = gcore_cdn_origin_group.example.id
  origin_protocol = "HTTPS"

  options = {
    proxy_connect_timeout = {
      enabled = true
      value   = "4s"
    }
    proxy_read_timeout = {
      enabled = true
      value   = "10s"
    }
  }
}
```
