grpc_read_timeout
Sets the timeout for reading responses from a gRPC server in NGINX.
Description
The grpc_read_timeout directive defines the maximum time interval that NGINX will wait for a response from a gRPC backend server after establishing a connection. This timeout is critical for controlling how long the server should keep waiting for a reply before giving up and closing the connection. It allows administrators to fine-tune the server's responsiveness and resource management by avoiding long stalling times where a request hangs indefinitely.
This directive can be specified in three contexts: http, server, and location. Its value is specified in time format (e.g., '30s' for 30 seconds). The directive's value must be a valid time span, which can be specified in seconds, minutes, or hours. If the response is not received within the specified timeout period, NGINX will return an error to the client, allowing for better fault tolerance in services that might experience delays.
Setting an appropriate grpc_read_timeout value is crucial, especially in production scenarios where gRPC services might exhibit varying response times depending on loads. A timeout that is too short may lead to unnecessary retries or failures, while a timeout that is excessively long may degrade the responsiveness of the application as requests may hang unnecessarily.
Config Example
location /example {
grpc_pass grpc://backend;
grpc_read_timeout 30s;
}Make sure to specify the timeout in the correct format (e.g., '30s').
Setting a very short timeout may lead to frequent errors and retries.
If not set, the default 60 seconds may not be sufficient for certain gRPC operations.