fixed expressjs shutdown taking a long time
This commit is contained in:
@@ -60,6 +60,7 @@ services:
|
|||||||
context: ./expressjs
|
context: ./expressjs
|
||||||
|
|
||||||
container_name: expressjs
|
container_name: expressjs
|
||||||
|
stop_grace_period: 5s
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
- BASE_PATH=/manage
|
- BASE_PATH=/manage
|
||||||
|
|||||||
@@ -334,7 +334,7 @@ async function cleanupExpired() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(() => {
|
const cleanupTimer = setInterval(() => {
|
||||||
cleanupExpired().catch(() => undefined);
|
cleanupExpired().catch(() => undefined);
|
||||||
}, 60 * 1000);
|
}, 60 * 1000);
|
||||||
cleanupExpired().catch(() => undefined);
|
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>'));
|
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}`);
|
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