Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(node-server): add env variables for timeout setting in node-server runtimes #1944

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/content/2.deploy/10.runtimes/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions src/runtime/entries/node-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down