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) {