504 Gateway Time-out (sometimes a 502), and the NGINX logs of the service show:
Cause
Requests to a public port go through the ingress of the cluster before they reach your service. By default, the NGINX ingress waits at most 60 seconds between two reads of the response from your service, then gives up. This is an inactivity limit, not a limit on the total duration: a response that keeps sending data, such as a stream, can last longer. Your application keeps running, but the client has already received an error. There is no single “request timeout” field: NGINX has one timeout per step, and each is an advanced setting of the service.Fix on the NGINX ingress
1
Open the advanced settings of the service
In the Console, open the application, container or Helm service, go to Settings, then Advanced Settings.
2
Raise the timeouts
Set
network.ingress.proxy_read_timeout_seconds to a value above the duration of your longest request, for example 120 or 300. For long uploads, raise network.ingress.proxy_send_timeout_seconds too. For large downloads to slow clients, raise network.ingress.send_timeout_seconds.3
Redeploy the service
The new values apply only after the service is redeployed. Saving the settings is not enough.
Fix on the Gateway API
When the cluster advanced settingk8s.use_api_gateway is true, new services are exposed through the Gateway API instead of NGINX. Services created before the switch can still route through NGINX, where the network.ingress.* settings above apply. Check how your own service is exposed before changing settings. For a service exposed through the Gateway API, the network.ingress.* settings do not apply. Use these instead, then redeploy the service:
network.gateway_api.http_request_timeout_seconds: maximum time to wait for the complete response. Requests that take longer end with504 Gateway Timeout.envoy.gateway_api.http_request_timeout_seconds: the cluster-wide default, used by services that do not set their own value.
Before raising the timeout
A longer timeout keeps a connection and a worker busy for the whole request. For work that takes minutes, consider answering at once and processing in the background: put the job in a queue, return202 Accepted with an ID, and let the client poll for the result. A lifecycle job or a cron job can also run long tasks outside the request path.
If requests fail with 502 well before 60 seconds, the cause is not a timeout. See 502 Bad Gateway: recv() failed (104: Connection reset by peer).