grpc_send_timeout
Defines the timeout for sending gRPC responses to the client.
Description
The grpc_send_timeout directive in NGINX sets the maximum time limit within which the server should send a gRPC response to the client after a request has been processed. This directive is important for ensuring that client applications do not wait indefinitely for a response, which can help in managing resources and maintaining application performance. The directive works at various contexts such as http, server, and location, allowing you to set different timeout values based on the specific needs of your applications.
When the defined timeout period elapses, NGINX will terminate the connection and generate a gRPC status code representing the timeout error. This can be particularly useful in environments with many microservices, where quick failure responses are preferable to potentially endless waits for severely delayed services. The specified timeout is utilized only for sending the responses after the server has started sending them to the client, meaning that it does not affect the processing time of the request itself, only the interval for sending the final response packets.
The syntax for this directive is grpc_send_timeout time;, where time can be specified in various formats like 30s for thirty seconds or 1m for one minute, etc. It's crucial to select a timeout value that balances between allowing ample time for the response but also ensures that unresponsive services do not hinder the overall functionality of your application.
Config Example
location /api {
grpc_pass grpc://backend_service;
grpc_send_timeout 30s;
}Setting the timeout too low may lead to premature disconnections, causing unnecessary errors for legitimate requests.
Ensure that the timeout does not conflict with other timeout settings such as client_body_timeout or send_timeout, which can lead to unexpected behavior.