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
@@ -94,21 +94,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,
@@ -124,4 +110,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);
});
});
}
+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);
});
});
}
+19 -15
View File
@@ -94,21 +94,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);
})
@@ -117,4 +103,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);
});
});
}
+21 -17
View File
@@ -99,28 +99,12 @@ if (!cluster.worker) {
.catch(exitWorkerUngracefully);
});
process.on("SIGINT", () => {
stopping = true;
server
.stop()
.then(exitWorkerGracefully)
.catch(exitWorkerUngracefully);
});
process.on("SIGTERM", () => {
stopping = true;
server
.stop()
.then(exitWorkerGracefully)
.catch(exitWorkerUngracefully);
});
const _listener = (req, res): void => {
if (stopping) res.setHeader("Connection", "close");
listener(req, res);
};
Promise.all([db2.connect(), cache.connect()])
const initPromise = Promise.all([db2.connect(), cache.connect()])
.then(() => {
server.start(SERVICE_PORT, SERVICE_ADDRESS, ssl, _listener);
})
@@ -129,4 +113,24 @@ if (!cluster.worker) {
throw err;
});
});
process.on("SIGINT", () => {
stopping = true;
initPromise.finally(() => {
server
.stop()
.then(exitWorkerGracefully)
.catch(exitWorkerUngracefully);
});
});
process.on("SIGTERM", () => {
stopping = true;
initPromise.finally(() => {
server
.stop()
.then(exitWorkerGracefully)
.catch(exitWorkerUngracefully);
});
});
}