js_fetch_timeout
Sets the timeout for fetching responses in the NGINX JavaScript module.
Description
The js_fetch_timeout directive is utilized to specify the maximum amount of time, in milliseconds, that the NGINX JavaScript module (NJS) will wait for a fetch operation to complete. This is important when making asynchronous requests in your JavaScript code running within NGINX, ensuring that long-running requests don't lead to unresponsive services. The timeout applies to all fetch requests made from scripts that are utilizing the njs module, allowing developers to handle both success and error cases effectively due to timeout management.
When you set the js_fetch_timeout directive, it accepts a single argument, which defines the timeout duration in milliseconds. If the fetch operation does not complete within the specified time frame, NGINX will automatically terminate the request, preventing further processing and allowing for graceful error handling within your NJS scripts. This can aid in managing performance and resource utilization in applications where timely responses are critical, such as in API-driven environments.
It is important to note that this directive can be configured at the stream and stream server contexts, making it versatile for different server configurations. The timeouts should be set according to the expected network latency and the performance characteristics of the backend services being accessed through the fetch operations.
Config Example
js_fetch_timeout 5000;
Ensure that the timeout value is set appropriately; too low may cause legitimate requests to fail.
The directive applies only to fetch operations and does not affect other request timeouts defined in NGINX.
Values must be specified in milliseconds.