Do not timeout after 10s

This commit is contained in:
Michael Jackson 2018-08-25 17:35:52 -07:00
parent 741530ac92
commit 30cd271339
2 changed files with 20 additions and 18 deletions

View File

@ -71,21 +71,21 @@ function createServer(publicDir, statsFile) {
// Heroku dynos automatically timeout after 30s. Set our // Heroku dynos automatically timeout after 30s. Set our
// own timeout here to force sockets to close before that. // own timeout here to force sockets to close before that.
// https://devcenter.heroku.com/articles/request-timeout // https://devcenter.heroku.com/articles/request-timeout
server.setTimeout(25000, socket => { // server.setTimeout(25000, socket => {
const message = `Timeout of 25 seconds exceeded`; // const message = `Timeout of 25 seconds exceeded`;
socket.end( // socket.end(
[ // [
"HTTP/1.1 503 Service Unavailable", // "HTTP/1.1 503 Service Unavailable",
"Date: " + new Date().toGMTString(), // "Date: " + new Date().toGMTString(),
"Content-Length: " + Buffer.byteLength(message), // "Content-Length: " + Buffer.byteLength(message),
"Content-Type: text/plain", // "Content-Type: text/plain",
"Connection: close", // "Connection: close",
"", // "",
message // message
].join("\r\n") // ].join("\r\n")
); // );
}); // });
return server; return server;
} }

View File

@ -27,13 +27,15 @@ function startServer(id) {
serverConfig.port serverConfig.port
); );
}); });
server.timeout = 10000;
} }
throng({ throng({
workers: process.env.WEB_CONCURRENCY || 1, workers: process.env.WEB_CONCURRENCY || 1,
start: startServer,
lifetime: Infinity, lifetime: Infinity,
grace: 11000,
start: startServer // Heroku shuts down processes forcefully after 30 seconds,
// so make sure we exit before that happens.
// https://devcenter.heroku.com/articles/dynos#shutdown
grace: 25000
}); });