For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
Response idle timeouts
Set a response idle timeout to terminate responses where the body stops sending data.
About response idle timeouts
A response has two phases. First, the backend sends the response headers, which include the status code. Then, the backend sends the response body in one or more pieces, which are also referred to as frames. A short response sends the body in a single frame. A streamed response, such as an LLM completion, sends many frames over a long time.
A request timeout timer starts with the request and stops when the response headers arrive from the backend. After that point, the request timeout no longer applies, no matter how long the body takes. If the backend stalls halfway through the body, the client already has the status code, and the response stays open without another timer that ends it.
You can set a response idle timeout in the traffic.timeouts.responseIdle field of an AgentgatewayPolicy to terminate responses where the body stalled. The gateway waits for the next frame of the response body, and the timer restarts with every frame that arrives. If no frame arrives in time, the gateway ends the response. A stalled response ends quickly, while an active response can stream for as long as it needs. The response idle timeout does not apply to the wait for the response headers.
Before you begin
- Set up an agentgateway proxy.
- Install the httpbin sample app.
Set up a response idle timeout
Create an HTTPRoute for the
/drippath of the httpbin app. The/drippath sends its response one byte at a time, so you can stall the response body on purpose.kubectl apply -f- <<EOF apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: httpbin-idle namespace: httpbin spec: hostnames: - idle.example parentRefs: - name: agentgateway-proxy namespace: agentgateway-system rules: - matches: - path: type: PathPrefix value: /drip backendRefs: - name: httpbin port: 8000 EOFCreate an AgentgatewayPolicy that sets a response idle timeout of 2 seconds on the HTTPRoute.
Review the following table to understand this configuration.kubectl apply -f- <<EOF apiVersion: agentgateway.dev/v1alpha1 kind: AgentgatewayPolicy metadata: name: httpbin-idle namespace: httpbin spec: targetRefs: - group: gateway.networking.k8s.io kind: HTTPRoute name: httpbin-idle traffic: timeouts: responseIdle: 2s EOFSetting Description targetRefsThe HTTPRoute that the timeout applies to. You can also target an HTTPRoute rule or a Gateway listener. traffic.timeouts.responseIdleThe time that the gateway waits for the next frame of the response body from the backend. The timer restarts with every frame. Response processing and client backpressure do not count. When the time passes, the gateway ends the response. Send a request to the
/drippath. In the query string,numbytessets the number of bytes,durationsets the time that httpbin spreads the bytes over, anddelay=0sends the first byte right away. With these values, httpbin sends one byte every 3 seconds. The gateway forwards the response headers and the first byte. When the next byte does not arrive within 2 seconds, the gateway ends the response.curl -s -o /dev/null -w 'status=%{http_code} bytes=%{size_download} time=%{time_total}s exit=%{exitcode}\n' \ "http://$INGRESS_GW_ADDRESS:80/drip?duration=9&numbytes=3&delay=0" -H "host: idle.example"Example output:
status=200 bytes=1 time=2.007100s exit=18The client already has the
200status code when the timeout applies. The client gets a response that ends early instead of an error status code. Theexit=18value is the curl exit code for a partial file, which shows that the response was cut short.Send a request with different
numbytesanddurationvalues, so that httpbin sends one byte every half second. The whole response takes about 5 seconds, which is longer than the idle timeout. No gap between two bytes reaches 2 seconds, so the response completes.curl -s -o /dev/null -w 'status=%{http_code} bytes=%{size_download} time=%{time_total}s exit=%{exitcode}\n' \ "http://$INGRESS_GW_ADDRESS:80/drip?duration=5&numbytes=10&delay=0" -H "host: idle.example"Example output.
status=200 bytes=10 time=5.063975s exit=0
Cleanup
You can remove the resources that you created in this guide. Run the following commands.
kubectl delete AgentgatewayPolicy httpbin-idle -n httpbin
kubectl delete httproute httpbin-idle -n httpbin