grpc_connect_timeout

Sets the timeout for establishing a connection to a gRPC backend server.

Syntaxgrpc_connect_timeout time;
Defaultnone
Contexthttp, server, location
Arguments1

Description

The grpc_connect_timeout directive specifies the maximum time allowed for establishing a connection to a gRPC backend server, given in milliseconds. This timeout is crucial for ensuring that long or unresponsive connections do not delay the processing of client requests for an extended period. When the timeout is reached before a connection is successfully established, NGINX will abort the connection attempt and return an error to the client, effectively allowing your application to handle connection failures gracefully.

This directive can be placed in the http, server, or location contexts, allowing administrators to define connection timeouts that suit the specific requirements of their application's architecture. The timeout period can be set to any positive integer value; if set to zero, it will disable the timeout feature altogether, which is typically not recommended in a live environment where client responsiveness is critical. The most effective use of grpc_connect_timeout is to balance between connection latency and application performance, allowing for quick retries or alternative failovers if the backend service is not responsive.

Config Example

http {
    server {
        location / {
            grpc_pass grpc://backend;
            grpc_connect_timeout 500ms;
        }
    }
}

Setting too short a timeout may lead to frequent premature connection aborted errors, impacting user experience.

Disabling the timeout (setting to 0) can lead to long delays in error reporting if the backend service is unresponsive.

← Back to all directives