fixed expressjs shutdown taking a long time
This commit is contained in:
@@ -334,7 +334,7 @@ async function cleanupExpired() {
|
||||
}
|
||||
}
|
||||
|
||||
setInterval(() => {
|
||||
const cleanupTimer = setInterval(() => {
|
||||
cleanupExpired().catch(() => undefined);
|
||||
}, 60 * 1000);
|
||||
cleanupExpired().catch(() => undefined);
|
||||
@@ -804,6 +804,23 @@ app.use((req, res) => {
|
||||
res.status(404).send(renderPage('Nicht gefunden', '<p class="card">Seite nicht gefunden.</p>'));
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
const server = app.listen(port, () => {
|
||||
console.log(`Express server listening on ${port} with base path ${basePath}`);
|
||||
});
|
||||
|
||||
function shutdown(signal) {
|
||||
clearInterval(cleanupTimer);
|
||||
server.close(() => {
|
||||
db.close(() => {
|
||||
console.log(`Shutdown complete (${signal}).`);
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
setTimeout(() => {
|
||||
console.error('Forced shutdown after timeout.');
|
||||
process.exit(1);
|
||||
}, 5000).unref();
|
||||
}
|
||||
|
||||
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
||||
process.on('SIGINT', () => shutdown('SIGINT'));
|
||||
|
||||
Reference in New Issue
Block a user