Fix occasional exceptions on SIGINT and SIGTERM

This commit is contained in:
Zaid Abdulla committed 2019-09-09 02:14:12 -07:00
1 parent 6f0e1d66ce
commit 1c9aa493c6
6 files changed
+95 -66

No files matched your search

+19 -15
View File
@@ -90,21 +90,7 @@ if (!cluster.worker) {
.catch(exitWorkerUngracefully);
});
process.on("SIGINT", () => {
server
.stop()
.then(exitWorkerGracefully)
.catch(exitWorkerUngracefully);
});
process.on("SIGTERM", () => {
server
.stop()
.then(exitWorkerGracefully)
.catch(exitWorkerUngracefully);
});
Promise.all([db.connect(), cache.connect()])
const initPromise = Promise.all([db.connect(), cache.connect()])
.then(() => {
server.start(SERVICE_PORT, SERVICE_ADDRESS, ssl, listener);
})
@@ -113,4 +99,22 @@ if (!cluster.worker) {
throw err;
});
});
process.on("SIGINT", () => {
initPromise.finally(() => {
server
.stop()
.then(exitWorkerGracefully)
.catch(exitWorkerUngracefully);
});
});
process.on("SIGTERM", () => {
initPromise.finally(() => {
server
.stop()
.then(exitWorkerGracefully)
.catch(exitWorkerUngracefully);
});
});
}