Skip to content

Commit 9dbd8d7

Browse files
AdamKatzDevijjk
andauthored
feat(standalone): allow configuring KEEP_ALIVE_TIMEOUT via env var (#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 <[email protected]>
1 parent 539cca8 commit 9dbd8d7

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/next/src/build/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,7 +1935,15 @@ const server = http.createServer(async (req, res) => {
19351935
})
19361936
const currentPort = parseInt(process.env.PORT, 10) || 3000
19371937
const hostname = process.env.HOSTNAME || 'localhost'
1938+
const keepAliveTimeout = parseInt(process.env.KEEP_ALIVE_TIMEOUT, 10);
19381939
1940+
if (
1941+
!Number.isNaN(keepAliveTimeout) &&
1942+
Number.isFinite(keepAliveTimeout) &&
1943+
keepAliveTimeout >= 0
1944+
) {
1945+
server.keepAliveTimeout = keepAliveTimeout
1946+
}
19391947
server.listen(currentPort, (err) => {
19401948
if (err) {
19411949
console.error("Failed to start server", err)

0 commit comments

Comments
 (0)