From 7ad0cd99da983abf4765cee1fe9a1d4a4b0d32ba Mon Sep 17 00:00:00 2001 From: lastmirage Date: Wed, 22 Nov 2023 17:28:50 +0900 Subject: [PATCH 1/2] feat: add env variables for setting timeout --- src/runtime/entries/node-server.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/runtime/entries/node-server.ts b/src/runtime/entries/node-server.ts index 3ed6c48b90..79ee267fe3 100644 --- a/src/runtime/entries/node-server.ts +++ b/src/runtime/entries/node-server.ts @@ -23,6 +23,14 @@ const host = process.env.NITRO_HOST || process.env.HOST; const path = process.env.NITRO_UNIX_SOCKET; +const requestTimeout = (destr(process.env.NITRO_NODE_REQUEST_TIMEOUT) || 300000) as number +const keepAliveTimeout = (destr(process.env.NITRO_NODE_KEEPALIVE_TIMEOUT) || 5000) as number +const headersTimeout = Math.min(destr(process.env.NITRO_NODE_HEADERS_TIMEOUT) || 60000, requestTimeout) + +server.requestTimeout = requestTimeout +server.keepAliveTimeout = keepAliveTimeout +server.headersTimeout = headersTimeout + // @ts-ignore const listener = server.listen(path ? { path } : { port, host }, (err) => { if (err) { From c989cd5b311b00b249f3d7b6063d08bc38768e6f Mon Sep 17 00:00:00 2001 From: lastmirage Date: Wed, 22 Nov 2023 17:29:24 +0900 Subject: [PATCH 2/2] docs(node): add timeout setting descriptions --- docs/content/2.deploy/10.runtimes/node.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/content/2.deploy/10.runtimes/node.md b/docs/content/2.deploy/10.runtimes/node.md index df3dedac34..2f5b38de13 100644 --- a/docs/content/2.deploy/10.runtimes/node.md +++ b/docs/content/2.deploy/10.runtimes/node.md @@ -44,6 +44,9 @@ You can customize server behavior using following environment variables: - `NITRO_SHUTDOWN_SIGNALS` - Allows you to specify which signals should be handled. Each signal should be separated with a space. Defaults to `'SIGINT SIGTERM'`. - `NITRO_SHUTDOWN_TIMEOUT` - Sets the amount of time (in milliseconds) before a forced shutdown occurs. Defaults to `'30000'` milliseconds. - `NITRO_SHUTDOWN_FORCE` - When set to true, it triggers `process.exit()` at the end of the shutdown process. If it's set to `'false'`, the process will simply let the event loop clear. Defaults to `'true'`. +- `NITRO_NODE_REQUEST_TIMEOUT` - Sets the timeout value in milliseconds for receiving the entire request from the client. Defaults to `'300000'` milliseconds. +- `NITRO_NODE_KEEPALIVE_TIMEOUT` - The number of milliseconds of inactivity a server needs to wait for additional incoming data, after it has finished writing the last response, before a socket will be destroyed. If the server receives new data before the keep-alive timeout has fired, it will reset the regular inactivity timeout, i.e., server.timeout. Defaults to `'5000'` milliseconds. +- `NITRO_NODE_HEADERS_TIMEOUT` - Limit the amount of time the parser will wait to receive the complete HTTP headers. Defaults to minimum between `'60000'` or `NITRO_NODE_REQUEST_TIMEOUT` milliseconds. ## Cluster mode