Idle timeouts
Set an idle timeout for HTTP/1 traffic to terminate the connection to a downstream or upstream service if there are no active streams.
About idle timeouts
An idle timeout configures the time a connection between a downstream client and an upstream service can stay open without sending any data or bytes.
In HTTP/1.1, connections are usually kept alive so you can reuse them for multiple requests. For example, a request to your upstream service might include a database to retrieve data. If an idle timeout is set too low, the gateway proxy might terminate the connection to the downstream client if the database is slow to respond. This can lead to multiple issues on the client side, including silent connection closures, protocol errors, or increased latency, because the client must establish a new connection in order to proceed. Long idle timeouts however can cause resource exhaustion on the gateway proxy and increased latency for clients, because they need to wait for a new connection to open up on the gateway proxy.
Note that idle timeouts do not configure how long an upstream service can take to respond to your request. Use request timeouts for this scenario instead.
Before you begin
- Set up an agentgateway proxy.
- Install the httpbin sample app.
Set up idle timeouts
-
Create an AgentgatewayPolicy with the idle timeout configuration. In this example, you apply an idle timeout of 30 seconds.
kubectl apply -f- <<EOF apiVersion: agentgateway.dev/v1alpha1 kind: AgentgatewayPolicy metadata: name: idle-time namespace: agentgateway-system spec: targetRefs: - kind: Gateway name: agentgateway-proxy group: gateway.networking.k8s.io frontend: http: http1IdleTimeout: 30s EOF -
Verify that the gateway proxy is configured with the idle timeout.
-
Port-forward the gateway proxy on port 15000.
kubectl port-forward deployment/agentgateway-proxy -n agentgateway-system 15000 -
Get the config dump and verify that the idle timeout policy is set as you configured it.
Example
jqcommand:curl -s http://localhost:15000/config_dump | jq '[.policies[] | select(.policy.frontend != null and .policy.frontend.hTTP != null and .policy.frontend.hTTP.http1IdleTimeout != null)] | .[0]'Example output:
http://localhost:15000/config_dump1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29{ "key": "frontend/agentgateway-system/idle-time:frontend-http:agentgateway-system/agentgateway-proxy", "name": { "kind": "AgentgatewayPolicy", "name": "idle-time", "namespace": "agentgateway-system" }, "target": { "gateway": { "gatewayName": "agentgateway-proxy", "gatewayNamespace": "agentgateway-system", "listenerName": null } }, "policy": { "frontend": { "hTTP": { "maxBufferSize": 2097152, "http1MaxHeaders": null, "http1IdleTimeout": "30s", "http2WindowSize": null, "http2ConnectionWindowSize": null, "http2FrameSize": null, "http2KeepaliveInterval": null, "http2KeepaliveTimeout": null } } } }
-
Cleanup
You can remove the resources that you created in this guide. Run the following commands.
kubectl delete AgentgatewayPolicy idle-time -n agentgateway-system