From e3528a1543c0fbdf026c4e3a08bb68874b91f8bf Mon Sep 17 00:00:00 2001 From: Colin Casey Date: Tue, 5 Aug 2025 15:01:53 -0300 Subject: [PATCH] Change the default Keep-Alive timeout to 95 seconds For consistency with the timeouts used by other languages: - https://github.com/heroku/heroku-buildpack-php/pull/823 - https://github.com/heroku/ruby-getting-started/pull/190 - https://github.com/heroku/python-getting-started/pull/263 --- index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/index.js b/index.js index d084afa84b..19d020f11f 100644 --- a/index.js +++ b/index.js @@ -18,6 +18,14 @@ const server = app.listen(port, () => { console.log(`Listening on ${port}`) }) +// The number of seconds an idle Keep-Alive connection is kept open. This should be greater than the Heroku Router's +// Keep-Alive idle timeout of 90 seconds: +// - to ensure that the closing of idle connections is always initiated by the router and not the Node.js server +// - to prevent a race condition if the router sends a request to the app just as Node.js is closing the connection +// https://devcenter.heroku.com/articles/http-routing#keepalives +// https://nodejs.org/api/http.html#serverkeepalivetimeout +server.keepAliveTimeout = 95 * 1000 + process.on('SIGTERM', async () => { console.log('SIGTERM signal received: gracefully shutting down') if (server) {