preread_timeout
Sets the timeout for the prereading phase of a stream connection.
Description
The preread_timeout directive in the NGINX Stream Core module specifies the limit for the time that the server will wait in the prereading state before closing an idle connection. During this state, NGINX is waiting for the client to send its complete request, such as data packets in TCP stream processing. If the client does not send data within the specified timeout period, NGINX will terminate the connection to conserve resources and to prevent potential denial of service attacks. In essence, it defines how long NGINX will remain patient during the initial phase of a stream transaction before taking action to close the connection.
This directive is particularly useful in environments where sustained idle connections might lead to resource exhaustion, which can hamper overall server performance. The parameter for this directive is a time value, specified in seconds, minutes, or hours, similar to other timeout directives in NGINX configurations. It is important for administrators to carefully balance this timeout period with the expected behavior of clients in their network, as setting it too low could inadvertently disrupt valid connections that may experience latency in their data transmissions.
Config Example
stream {
upstream backend {
server backend1.example.com;
server backend2.example.com;
}
server {
listen 12345;
preread_timeout 30s;
proxy_pass backend;
}
}Setting preread_timeout too low may cause legitimate connections to be dropped due to delays in data transmission.
Ensure that the configured timeout allows enough time for clients to establish connections, especially in high-latency networks.