Skip to content

Commit

Permalink
feat(standalone): allow configuring KEEP_ALIVE_TIMEOUT via env var (#…
Browse files Browse the repository at this point in the history
…46052)

Resolves #39689, partially resolves #28642 (see notes below)
Inspired by #44627

In #28642 it was also asked to expose `server.headersTimeout`, but it is
probably not needed for most use cases and not implemented even in `next
start`. It was needed to change this option before
nodejs/node#27363.
There also exists a rare bug that is described here
nodejs/node#32329 (comment). To fix
this exposing `server.headersTimeout` might be required both in
`server.js` and in `next start`.

Co-authored-by: JJ Kasper <jj@jjsweb.site>
  • Loading branch information
AdamKatzDev and ijjk committed Mar 17, 2023
1 parent 539cca8 commit 9dbd8d7
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/next/src/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1935,7 +1935,15 @@ const server = http.createServer(async (req, res) => {
})
const currentPort = parseInt(process.env.PORT, 10) || 3000
const hostname = process.env.HOSTNAME || 'localhost'
const keepAliveTimeout = parseInt(process.env.KEEP_ALIVE_TIMEOUT, 10);
if (
!Number.isNaN(keepAliveTimeout) &&
Number.isFinite(keepAliveTimeout) &&
keepAliveTimeout >= 0
) {
server.keepAliveTimeout = keepAliveTimeout
}
server.listen(currentPort, (err) => {
if (err) {
console.error("Failed to start server", err)
Expand Down

0 comments on commit 9dbd8d7

Please sign in to comment.