HTTP 504 Gateway Timeout
error.
This feature helps to maintain system stability and prevents unresponsive or long-running tasks from affecting the overall performance of the system. The enforced timeout can be customized and configured to suit specific requirements, providing control over resource allocation and ensuring optimal system functionality.
HTTP 504 Gateway Timeout
error returned to the client.
504 Gateway Timeout
to the client.
When working with Tyk OAS APIs the enforced timeout is configured in the Tyk OAS API Definition. You can do this via the Tyk Dashboard API or in the API Designer.
If you’re using the legacy Tyk Classic APIs, then check out the Tyk Classic page.
Configuring an enforced timeout in the Tyk OAS API Definition
The design of the Tyk OAS API Definition takes advantage of the operationId
defined in the OpenAPI Document that declares both the path and method for which the middleware should be added. Endpoint paths
entries (and the associated operationId
) can contain wildcards in the form of any string bracketed by curly braces, for example /status/{code}
. These wildcards are so they are human readable and do not translate to variable names. Under the hood, a wildcard translates to the “match everything” regex of: (.*)
.
The enforced timeout middleware (enforceTimeout
) can be added to the operations
section of the Tyk OAS Extension (x-tyk-api-gateway
) in your Tyk OAS API Definition for the appropriate operationId
(as configured in the paths
section of your OpenAPI Document).
The enforceTimeout
object has the following configuration:
enabled
: enable the middleware for the endpointvalue
: the duration of the upstream request timerGET /status/200
endpoint. It will configure a timer that will expire (timeout
) 3 seconds after the request is proxied to the upstream service. If the upstream response is not received before the expiry of the timer, that request will be terminated and Tyk will return 504 Gateway Timeout
to the client.
The configuration above is a complete and valid Tyk OAS API Definition that you can import into Tyk to try out the enforced timeout.
Configuring an enforced timeout in the API Designer
Adding the enforced timeout to your API endpoints is easy when using the API Designer in the Tyk Dashboard, simply follow these steps:
Step 1: Add an endpoint
From the API Designer add an endpoint that matches the path and method to which you want to apply the middleware.
504 Gateway Timeout
to the client.
When working with Tyk Classic APIs the enforced timeout is configured in the Tyk Classic API Definition. You can do this via the Tyk Dashboard API or in the API Designer.
If you’re using the newer Tyk OAS APIs, then check out the Tyk OAS page.
If you’re using Tyk Operator then check out the configuring an enforced timeout in Tyk Operator section below.
Configuring an enforced timeout in the Tyk Classic API Definition
To configure an enforced timeout you must add a new hard_timeouts
object to the extended_paths
section of your API definition.
It has the following configuration:
path
: the endpoint pathmethod
: the endpoint HTTP methodtimeout
: the duration of the upstream request timerGET /status/200
endpoint. It will configure a timer that will expire (timeout
) 3 seconds after the request is proxied to the upstream service.
If the upstream response is not received before the expiry of the timer, that request will be terminated and Tyk will return 504 Gateway Timeout
to the client.
Configuring an enforced timeout in the API Designer
You can use the API Designer in the Tyk Dashboard to configure the enforced timeout middleware for your Tyk Classic API by following these steps.
Step 1: Add an endpoint for the path and select the Enforced Timeout plugin
From the Endpoint Designer add an endpoint that matches the path for which you want to deploy the enforced timeout. Select the Enforced timeout plugin.
hard_timeouts
object within the extended_paths
section of the API Definition.
The example API Definition below configures an API to listen on path /httpbin-timeout-breaker
and forwards requests upstream to http://httpbin.org. A hard timeout value of 2 seconds is configured for path /delay/{delay_seconds}
. This will return a 504 Gateway Timeout
response to the client if the upstream response is not received before expiry of the timer.